![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Call me Chuck
|
Reading text from a file.
I am having a problem reading text from a file. I thought I have followed every rule for opening and reading a file but it is still not working. Note, I am not completely done with this, I still need to add some precautionary code for bad files. The problem is that the program seems to have problems opening the file and I can't figure out what is wrong, here is the source:
C++ Syntax (Toggle Plain Text)
C++ Syntax (Toggle Plain Text)
Thanks for your time, sorry if I didn't explain well enough.
__________________
sqrt(-1) <3 3.14 98% of the teenage population will try, does or has tried smoking pot. If you're one of the 2% who hasn't, copy & paste this into your signature |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,254
Rep Power: 5
![]() |
Re: Reading text from a file.
Most obvious thing to check: does the file exist?
A common occurrence is for the current working directory differs from the directory that the file ("test.txt") is in - i.e. the file is not in the current working directory.
__________________
Dear God So far today I've done all right. I haven't been grumpy yet. But in a few minutes, God, I'm going to get out of bed, and from then on I'm going to need a lot more help. AMEN |
|
|
|
|
|
#3 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
Re: Reading text from a file.
I usually put the text file in the same directory as the executable (\Debug for VS) and it finds it without a full path. But it would make your life easier if you specify the full path of the file (make sure to escape \ with \\).
|
|
|
|
|
|
#4 | |
|
hi: for(;;) goto hi;
|
Re: Reading text from a file.
Quote:
__________________
How do you play Religious Roulette? Stand around in a circle and blaspheme till someone gets struck by lightning. |
|
|
|
|
|
|
#5 |
|
Call me Chuck
|
Re: Reading text from a file.
Hmmm... I've checked to make sure the file exists, as a matter of fact I wrote it by hand. I did put it in \debug like I'm supposed to but I'm still getting my error. Perplexing...
__________________
sqrt(-1) <3 3.14 98% of the teenage population will try, does or has tried smoking pot. If you're one of the 2% who hasn't, copy & paste this into your signature |
|
|
|
|
|
#6 |
|
Call me Chuck
|
Re: Reading text from a file.
I have it working right but the problem is I can't get the
getline() function to read a whole line into the temp object. Any help would be appreciated, thanks.
__________________
sqrt(-1) <3 3.14 98% of the teenage population will try, does or has tried smoking pot. If you're one of the 2% who hasn't, copy & paste this into your signature |
|
|
|
|
|
#7 |
|
Professional Programmer
Join Date: Oct 2006
Posts: 311
Rep Power: 3
![]() |
Re: Reading text from a file.
did you read the for loop peaceofpi quotes? its wrong. lol
|
|
|
|
|
|
#8 |
|
Call me Chuck
|
Re: Reading text from a file.
AHH!! I'm so stupid. lol That is too obvious! I'll fix it and come back with the results.
__________________
sqrt(-1) <3 3.14 98% of the teenage population will try, does or has tried smoking pot. If you're one of the 2% who hasn't, copy & paste this into your signature |
|
|
|
|
|
#9 |
|
Call me Chuck
|
Re: Reading text from a file.
It is now working just as I wanted! Thanks everyone.
__________________
sqrt(-1) <3 3.14 98% of the teenage population will try, does or has tried smoking pot. If you're one of the 2% who hasn't, copy & paste this into your signature |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Reading file - convert ASCII to characters | Matt42 | C++ | 8 | Jan 2nd, 2008 6:49 PM |
| Adding more info to a text file without erasing | crawforddavid2006 | C# | 2 | Apr 11th, 2007 3:10 PM |
| Reading contents of text file then printing out, not working. | chillypacman | PHP | 5 | Jun 19th, 2006 7:29 AM |
| reading a random line from a text file | cloud- | Visual Basic | 11 | Apr 8th, 2005 2:34 PM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C++ | 0 | Mar 2nd, 2005 5:12 PM |