![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Programmer
Join Date: Jan 2005
Location: Albany, NY
Posts: 43
Rep Power: 0
![]() |
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... |
|
|
|
|
|
#12 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 751
Rep Power: 3
![]() |
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.
|
|
|
|
|
|
#13 |
|
Programmer
Join Date: Jan 2005
Location: Albany, NY
Posts: 43
Rep Power: 0
![]() |
I can't open it before the loop becuase it's reading from 5 different files and each needs to be opened.
__________________
meh... |
|
|
|
|
|
#14 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 751
Rep Power: 3
![]() |
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 ![]() |
|
|
|
|
|
#15 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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
__________________
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 |
|
|
|
![]() |
| 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 |
| [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 |