Soo I want to rewrite Lines which has words like "Name" "File" into another File.
I tired myself making this , but it seems that I dont understand fstream,ofstream and ifstream enough.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
ifstream read("File.txt",ios_base::app);
ofstream write("File2.txt", std::ios::app);
string line;
string currentLine;
string ID="Name";
if (read.is_open()) {
while (!read.eof()) {
getline(read, line);
currentLine= line;
size_t found = currentLine.find(ID);
if (found != string::npos)
write<<currentLine<< endl;
}
}
This only works if I put manually Data as string.
It is needed for program to read File.txt (line by line) and if it finds String or Substring "name" to transcript that line into File2.txt
I commented out two lines with streams referring to files.
I (temporarily) replaced them with streams allowing you to run them in cpp.sh and see the output.
I'm sure that you can go back to filestreams without thinking too hard ...
Just un-comment the two lines with ifstream and ofstream
Then comment out the lines associated with istringstream and ostream.
Then, lo and behold, you will no longer be using your stringstream nemesis and you will have stream "in" attached to an input file and "out" attached to an output file.