Hi everyone, I'm new to this forum and require some assistance.
I have to make a program that reads from a file and prints the first three words from after the first three commas, which I've done.
However, I have to allow the user to define the name of the input file, meaning that the actual name of the file has to dynamically change depending on what the user chooses. As in, if they enter "asdf" when prompted, the file that the C++ program reads from will be named "asdf."
string filename, after_comma1, after_comma2, after_comma3;
cout << "This program will let the user choose a filename. Then, it will show the first\nword following each of the first three commas in the file." << endl;
cout << "\nPlease enter your desired filename." << endl;
cin >> filename;
filename = filename + ".dat";
inData >> after_comma1;
cout << after_comma1 << endl;
inData >> after_comma2;
cout << after_comma2 << endl;
inData >> after_comma3;
cout << after_comma3 << endl;
Right now, if you enter the name of the input file as it was created, aptly named "input.dat" (you just have to enter the name as "input" ) the program works.