我有一個非常長的.txt文件,我想使用getline
進行流式處理。我想輸入這個整個文本文檔,然後通過一個過程運行它。連續輸入使用getline到txt文檔結尾的行C++
然後,我想通過使用不同值的相同過程來運行該新字符串,等等2次。
到目前爲止,我有通過運行一個程序的整個文件
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void flag(string & line, int len);
void cut(string & line, int numb);
int main()
{
string flow;
ifstream input;
ofstream output;
input.open(filename.c_str()); //filename ...
output.open("flow.txt");
while (!input.fail())
getline(input, flow);
flag(flow, 10);
flag(flow, 20);
cut(flow, 20);
cut(flow, 3);
output << flow;
return 10;
}
//procedures are defined below.
我有麻煩。我將如何使用getline
進行流式處理。
我已經試過getline
,infile.fail
,npos
等
刪除'return'語句。 – 2013-03-12 20:32:04
@AlexChamberlain:爲什麼?! 'return'不在'loop'裏面。 – deepmax 2013-03-12 20:33:23
@MM。這就是爲什麼你應該總是使用'{}'! – 2013-03-12 21:08:03