爲什麼下面的代碼無法正常工作C++追加到字符串並寫入文件
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
int main(){
string data;
int i=0;
while(i <= 5){
i++;
data += i;
data += "\n";
}
ofstream myfile;
myfile.open ("data.txt");
myfile << data;
myfile.close();
}
它應該追加數然後換行符,並將其寫入一個文件(即沒有按還沒有)。
的文件應該是這樣的......
1
2
3
4
5
什麼是錯的代碼?
那麼,到目前爲止,您會從中得到什麼? – James 2010-08-24 16:29:55
哪裏的main()??? – 2010-08-24 16:30:53
該程序不會編譯。 main()在哪裏? – riwalk 2010-08-24 16:32:14