0
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream stream1("source.txt");
string line ;
ofstream stream2("target.txt");
while(std::getline(stream1, line))
{
stream2 << line << endl;
cout << line << endl;
}
stream1.close();
stream2.close(); return 0;
}
我怎样才能使这个代码让这个如果找到的话,例如“HELLO”的行会保存到STREAM2整行?其余的行如果没有该字不会保存到stream2。如果一行包含特定单词保存它
基本上,如果它在阅读时在一行中找到单词“HELLO”。它输出它。如果不是,则跳过该行。
是你的问题如何测试字符串是否出现在行?或者如何写入输出流?一旦你知道如何做到这一点,这应该是微不足道的。 – templatetypedef 2012-02-04 07:54:44
对你的问题不太直接,但你知道“grep”吗? – 2012-02-04 07:55:39
基本上,如果它在阅读时在一行中找到单词“你好”。它输出它。如果不是,则跳过该行。 – mystycs 2012-02-04 07:57:00