Hello everyone,
I have an assignment that I am working on for a class at my school. I have to write a program that will open a .txt file and read/copy the code to a string. This is probably really easy, but I guess my knowledge thus far is a bit lacking. I am not asking for you guys to finish my code by any means, I enjoy figuring most things out for myself, but have been stuck for a bit, and just need to be pointed in the right direction.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
ifstream inFile;
string fileName;
string inputString;
cout << "Please enter the first input file name:\n";
cin >> fileName;
cout << fileName << endl << endl;
inFile.open(fileName.c_str());
getline(inFile, inputString);
cout << "First line of file: " << inputString << endl;
return 0;
}
I am using Visual Studio 2008 and I have all of my files(the source files and the .txt files added to my working directory. I am not sure if I have to specify the path as to where the files are located or what is going on. When I run the code, All I get on the final cout statement is the "First line of file:", and nothing where the inputString is supposed to print. Any help you guys can offer would be great. Thanks in advance.
Joshua