opening a file

I'm trying to read data from a file, but my code is not working. What is wrong with the code? And, I followed a book by Tony Gaddis.


#include<iostream>
#include<fstream>
using namespace std;

int main()
{
int number;
ifstream inputfile;
inputfile.open("numbers.txt");
inputfile.seekg (0, ios::end);

if(inputfile)
{
while(inputfile>>number)
{
cout<<number<<endl;
}
}
else
cout<<"wrong";
inputfile.close();
return 0;
}
I don't think you need inputfile.seekg (0, ios::end);
Can anyone tell me what is wrong with my code here:

void InterpretBatch(istringstream& linein)
{
string line, filename;
linein>>filename;
ifstream input(filename.c_str());


	if (input.is_open())
	{
		while(getline(input,line))
		{
			cout<<line<<endl;
		}
		input.close();						//close the file
	}
	else
	{cout<<"Could not Open file"<<endl;}
}


I'm using visual studio 2012. The code runs, but when I go over the input(filename.c_str()); in the debugger I can see that it doesn't want to open the file name I give it because it under 'input' in Locals it reads {_Filebuffer={_Set_eback=0x00000000 <NULL> _Set_egptr=0x00000000 <NULL> _Pcvt=0x00000000 {...} ...} } std::basic_ifstream<char,std::char_traits<char> >
Topic archived. No new replies allowed.