我有一個文件,我需要輸入在我的程序用C++ .. 文件結構從C++中的文件獲取輸入?
100
150
245 467 367 367
使用get()
只讀取第一行......再次使用get()
沒有幫助.. PLS建議最好的方法。 感謝
我有一個文件,我需要輸入在我的程序用C++ .. 文件結構從C++中的文件獲取輸入?
100
150
245 467 367 367
使用get()
只讀取第一行......再次使用get()
沒有幫助.. PLS建議最好的方法。 感謝
參見:http://en.cppreference.com/w/cpp/io/basic_ifstream
嘗試這樣:
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()
{
ifstream stream("file.txt");
string foo;
while(stream >> foo)
cout << foo << endl;
return 0;
}
輸出:
100
150
245
467
367
367
可以使用流運營商在一次提取一個數字。
更新您的問題,如果這沒有回答它作爲它很難告訴你想要做什麼的一種。
100個數據在換行後...由html問題自動格式化...請考慮 – Sumit