Output from a .txt file issue

I am trying to get my text file to be read and then have it output. I keep getting a blank black cmd box. Any hints? I've used a similar format of this for inputting information from a text to make calculations and then output those calculations, but for some reason I can't get the actual text from a .txt file to appear

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
ifstream notepad("studentscores.txt");
string name;
int score;

while (notepad >> name >> score)
{
cout << name << score;
}




return 0;
}
You have to open the file before you can read it.
Ok, so.. I open the file, why am I still getting just a black cmd without any info

int main()
{
ifstream notepad("student-scores.txt");
string name;
int score;
notepad.open("student-scores.txt");
while (notepad >> name >> score)
{
cout << name << score;
}




return 0;
}

Are you sure the file is actually opened?

1
2
3
4
if(!notepad.is_open())
	cerr << "Problem opening file...";
else
        // proceed  


I am not sure if it matters or not, but this is all you need to declare the stream.

ifstream notepad;
Topic archived. No new replies allowed.