Hard coding a text file

So for this project I am given a text file that I need to hard code and read. Usually we have to ask the user to input the text file but this time there is only 1 text file. How would I open a text file automatically when the program is ran?

1
2
3
4
5
6
7
8
9
10
11
12
13
cout << "Enter valid filename: ";											
cin >> filename;															
inputFile.open(filename.c_str());											

while(!inputFile)															
{
	inputFile.clear();
	cin.clear();
	cin.sync();
	cout << "Re-Enter a valid filename: ";									
	cin >> filename;
	inputFile.open(filename.c_str());				
}


That is what my function for opening a file normally looks like. How would I change it so it opens without asking for input?
1
2
  string filename = "c:\\path\\fille.txt";
  inputFile.open(filename.c_str());	
Ok thx, but lets say my teacher has a different path to the text file. Is there a way to make it so she wouldn't have to change my code to read it?
try this

1
2
3
4
5
6
7
while(inputFile.is_open())
{
      cout << "Re-Enter a valid filename: ";
      cin >> filename;
      inputFile.close();
      inputFile.open(filename);
}
If you just put in the file name, the the program will look in the current folder, so instead of hard coding the path, the program would have to be ran from the folder with the text file.
Topic archived. No new replies allowed.