在C++ Ubunt 12.04中,我有一個名爲config.txt
的文件,其中包含user name
和password
。我有2 public static string
變量:USER
和PASSWORD
。這是我的代碼:我的cout有什麼問題?
// Read file from config
string text[2];
int count = 0;
while(!fin.eof()){
getline(fin,text[count]);
count++;
if(count == 2){
break;
}
}
CONNECTOR::USER = text[0];
CONNECTOR::PASSWORD = text[1];
string userAndPassword = CONNECTOR::USER + ":" + CONNECTOR::PASSWORD;
cout << CONNECTOR::USER << endl; // It's fine, right user: qsleader
cout << CONNECTOR::PASSWORD << endl; // ok, right password: 123456
cout <<"user and password: " << userAndPassword << endl; // It's weird text! Problem here!
奇怪的文本結果是::123456d password: qsleader
!!這不是我所期望的!但我不知道爲什麼會發生這種情況?任何人都可以給我一個建議嗎? (如果我打印:cout << "user and password: qsleader:123456"
,結果是好的!!)!
Sr,我的複製錯誤! –
你確定這只是一個複製錯誤嗎? – irrelephant
看看[這個問題](http://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong)。 – juanchopanza