Hi guys,
I frequently come to this forum for help but have never posted. I currently have an assignment in which i have to initialize a string and assign this strings value to what is inside a text file that a user will be giving.
most of the solutions to this problem i find online require me to use the ifstream class and to know the file name that will be submitted such as in the code below
#include<iostream>
#include<fstream>
using namespace std;
int main() {
ifstream myReadFile;
myReadFile.open("text.txt");
char output[100];
if (myReadFile.is_open()) {
while (!myReadFile.eof()) {
myReadFile >> output;
cout<<output;
}
}
myReadFile.close();
return 0;
}
I need a generalized solution to this problem that does not require me to assume the file name of my user's input (eg: "text.txt")
If you have the input in a string, just pass that as the parameter and it will work. We could give more specific help if you posted your code. Remember to use [code][/code] tags.