Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Jun 15th, 2005, 4:42 PM   #1
Cipher
Hobbyist Programmer
 
Cipher's Avatar
 
Join Date: Feb 2005
Location: /home/cipher
Posts: 123
Rep Power: 4 Cipher is on a distinguished road
Send a message via AIM to Cipher Send a message via MSN to Cipher
Using Fstream to read files

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.
__________________
And there was much rejoicing... Yay....
Cipher is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:38 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC