Ok, I want to read integers from a text file...a large sum of integers. The input is a regular text file, where each line is terminated with an end-of-line character. The file is gonna contain any valid ASCII symbol between 32 and 127. A number of strings ( no negative sign ). Like...
1+2+3+4+5
0 + 100
+492
+ 1000
Just some examples of input files. I want the output to be appended to a text file. If the output file does not exist, it should create it and append it after each run. Well, I find this to be tricky.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream myReadFile("text.txt");
string output;
while (getline(myReadFile, output)) {
cout << output << '\n';
}
}
So this would read the file. I know I gotta still change things so the input can be handled correctly. I want the frame first. So read it from the text file and then create one and put it in there. How exactly can I do this? Could I use ofstream ?
int main () {
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
Like this one? So first I would have ifstream and the ofstream comes right after it? This should creat the file. Maybe put the input into it, too. Sorry... kind of a a newbie here. I would appreciate if someone could help me with this!