爲什麼此代碼打印字符,而沒有第一個字符?它說ocalhost
而不是localhost
。感謝您的幫助。第一個字符在ifstream中消失
#include <winsock2.h>
#include <mysql/mysql.h>
#include <iostream>
#include <windows.h>
#include <fstream>
using namespace std;
int main() {
int b = 0;
char * pch;
int stringLength = 0;
char textRead[50];
ifstream infile("config.ini", ios::in | ios::binary);
if(!infile) {
cout << "ERROR: config.ini not found!\n";
system("pause");
exit(0);
}
infile >> textRead;
stringLength = strlen(textRead);
pch=strchr(textRead,'"');
while(pch != NULL) {
infile.seekg(pch-textRead-1);
infile >> textRead;
pch = strchr(pch+1,'"');
}
cout << textRead;
infile.close();
無法分辨'config.ini'的內容。 – 2010-11-18 19:11:27
你爲什麼要編寫解析INI文件的代碼呢?您明確使用Windows,因此請調用['GetPrivateProfileString'](http://msdn.microsoft.com/zh-cn/library/ms724353.aspx)以獲取所需的INI值。 – 2010-11-18 21:00:07