hello world 的程式我想大家都應該會了吧,故在這裏就不再累述。
那就從如何讀取一個文本文件開始好了,我也是google了半天,纔算正確輸出了
對了我使用的IDE是Code::Blocks,開源的小巧輕便
[color=brown]#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char s[1024];
char* path = "F:\\e_books\\cpp\\study\\file\\bin\\Debug\\file.txt";
fstream fh(path);
while(fh.getline(s,1024))
{
cout << s << endl;
}
fh.close();
return 0;
}[/color]
代碼我想在google中很多,我在這裏要講的是file path的問題,大家可以看到我現在使用的絕對路徑,但是我試了"file.txt","./file.txt"都讀不出內容來,還沒有找到解決辦法,等找到了再更新吧