在 C++,Ubunt 12.04 中,我有一个名为的文件config.txt
,其中包含user name
和password
. 我有 2 个public static string
变量: USER
和PASSWORD
. 这是我的代码:
// 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"
,结果很好!!)!