Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Aug 17th, 2006, 2:37 PM   #11
TCStyle
Programmer
 
Join Date: Jan 2005
Location: Albany, NY
Posts: 43
Rep Power: 0 TCStyle is on a distinguished road
Thanks! I used Narues / voids function and it works! I ran into another problem though. I want to read all the information in each file and then print it on its own line. Heres the script:
        myString = IntToString(x);
        File.open((myString + ".txt").c_str());
	if(File.is_open()) {
		string data;
		File>>data;
		cout << data;
		File.close();
	}

It is nested inside the for() loops so it should repeat it for all 5 files but it only reads content from the first!
__________________
meh...
TCStyle is offline   Reply With Quote
Old Aug 17th, 2006, 3:04 PM   #12
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 751
Rep Power: 3 Jimbo is on a distinguished road
Each time you open the file, you start reading from the beginning. Open it before the loop, and close it after the loop. You might also research the getline function if you want to read an entire line at a time.
Jimbo is offline   Reply With Quote
Old Aug 17th, 2006, 3:13 PM   #13
TCStyle
Programmer
 
Join Date: Jan 2005
Location: Albany, NY
Posts: 43
Rep Power: 0 TCStyle is on a distinguished road
I can't open it before the loop becuase it's reading from 5 different files and each needs to be opened.
__________________
meh...
TCStyle is offline   Reply With Quote
Old Aug 17th, 2006, 3:17 PM   #14
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 751
Rep Power: 3 Jimbo is on a distinguished road
oh, right, forgot that :o

are you incrementing x in your loop? maybe posting an extra couple lines of code on either end would help
Jimbo is offline   Reply With Quote
Old Aug 17th, 2006, 3:24 PM   #15
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Outer loop that determines file name
   Open file
   Inner loop that reads lines
      Read line
      If end of file, leave inner loop
   End inner loop
   Close file
End outer loop
Don't use a high-heel shoe to drive a nail and don't use the extraction operator to read an entire line. The stream has a getline method and the string class has a getline method. Read your documentation and choose the right tool.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Efficiency] Variables vs. Calculations kurt C 7 Dec 29th, 2005 2:39 PM
Dynamic memory - variables darkone916 C++ 4 Dec 7th, 2005 6:24 AM
Variables coldDeath Python 4 Aug 9th, 2005 11:35 AM
Assignment of numbers to variables without asking Haz C# 26 May 23rd, 2005 10:30 AM
Is it possible for me using session variables into a class? see07 C# 1 Mar 9th, 2005 5:32 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:01 PM.

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