HINTERNET hInternet, hFtpSession, hFile;
hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
hFtpSession = InternetConnect(hInternet, FTPHOST, INTERNET_DEFAULT_FTP_PORT,
FTPUSER, FTPPASS, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
hFile = FtpOpenFile(hFtpSession, argv[1], GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
DWORD rSize;
char tmp[2048];
string buffer;
while(InternetReadFile(hFile, tmp, 2048, &rSize) && rSize > 0)
{
buffer += (string)tmp;
}
cout << buffer;
InternetCloseHandle(hFile);
InternetCloseHandle(hFtpSession);
InternetCloseHandle(hInternet);
我有這個小程序從FTP服務器讀取文本文件到字符串,但在讀取字符串結尾有一些額外的字符。我想問題是與文本的大小,但我無法弄清楚。InternetReadFile返回文本結尾的額外字符
比如我想下載將被破壞這樣
MIICIDANBgkqhkiG9w0BAQEFAAOCAg0AMIICCAKCAgEAp2q+92EQPncY0sN6SMTC0yh05GpZ
FUEGATvUx/zcUrzdDTva5JKz0MztuCn3lnHmaUB6L97w8fuVOhJjj90ItH4FdUk4R9m50son
DSZ4ad5ZKi7WE7GApIq21vgM0zoG5sr0Xb6X41IQgvYF7i9nX4zKO2znRyD3uzBqkqkhWzbS
HI2euCdhmXfx2az0ynNKrcnQINaWowipc0LrW0Q9PWI1McCs4V5sz8GkBMpKENb3m/LBlSqz
TboC/9hiD9Yfclvk3wFeNGvsnUUDpwZipF9cBMVzmfyjA1gBDNLV8qcTXSortHaGeHdLpqIg
Qn3SpDol8gPRis7A7Hy4KjRS8Y/iZa8Nv9EmEeful6u3IHY0Qror/wOeST5WhaTynVBT0wgP
6GSMWsofwA3NttsFCw55z5c8GBEGP6Uo+jP/rdiYvednT0iV8Grp+XJ6zMFqYlVcLqAzQWLw
dfqve/lr8+OKfR9WvG6hvrVduTnoy+LBFF/QEVxAlZqymlXMm/hcO/TUoE1Kmon6FwID4Mek
nV1eb1aCmUIzxFHtPkMO0KFitmxa5EGwAFHRAjXrp2lUHIQSaWwVnsfoQgmrG9ux2I27w+WR
8kFdkqWrutFz2xn6ovVwla7Oj0iL2f9azNO2Z2KT/sBPwGmI67M9Ceih0YLD0w7Woy32H2aM
mIeK368CARE=
8
8不應該在那裏結束的密文。
'字符串'不是C類型。請不要將此問題標記爲「C」。另外,你不能在C中重載操作符(比如'buffer + = ...')這個問題與C無關。請編輯問題並關閉C標籤。 –