Ok I was reading "Sams: Teach yourself C++ in 21 Days" blah blah blah and I came across the section about using streams to read files. Soon after, I coded a CONSOLE(MS-DOS) Program to read a text file that I had typed. Here was the code in the book for reading files:
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
char filename[80];
cout << "enter filename where txt file is kept.";
cin >> filename:
ifstream fin(filename);
cout << "File Contents: "
char ch;
while (fin.get(ch)) /*Problem begins here..../*
cout << ch;
cout << "\n END OF FILE REACHED\n";
fin.close();
return 0;
}
I enter the file name. Which would be "C:\Documents and settings\Cipher\My Documents\My txt\Weapons List.txt" and
then it justs displays a blank line and "END OF FILE REACHED" then closes when I press enter? So I suppose it's not reading the file contents, did I just miss something such as a syntax error or do I maybe have to specify the text file itself?
Any help would be apperciated.