【发布时间】:2013-03-12 20:28:40
【问题描述】:
我有一个非常长的 .txt 文件,我想使用 getline 将其流式传输。我想输入整个文本文档,然后通过一个过程运行它。
然后我想通过相同的过程使用不同的值运行该新字符串,以此类推 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声明。 -
@AlexChamberlain:为什么?!
return不在loop内。 -
@MM。这就是为什么您应该始终使用
{}! -
@AlexChamberlain:是的,最好使用
{}并缩进代码,但删除return是无关紧要的。 -
@MM。是的,但这就是我误读的原因。