![]() |
|
#1
|
|||
|
|||
I/O streamsHello there,
I am new to this forum and I am new to c++. Anyway, I was doing so well in the class so far, oh boy, until the I/O chapter. I am so lost. The more i read, the more i am getting confused. Please help me. I save the input file below called (number.dat) in notepad. I don't know if I have to save in notepad or within c++ (..as to what...?) I am so confused with infile stuff. I know the biggest integers is 47. How do i get this 47 to output? the input file: 12 5 45 -3 13 -2 14 47 43 I have write those codes with the little that I was able to understand by reading 2 chapters on I/O streams. I'm hoping that someone here could help me because I'm so hopeless and need to turn in this lab by tuesday. Thank you so much in advance. Megan CPP / C++ / C Code:
|
|||
|
#2
|
|||
|
|||
Re: I so need help with I/O streamsIs it your job to decide the format of the file? If so, I would put one integer per line. That will make it easier to parse. Also, your code is all bad. Try doing it like this:
1) Open the file for reading 2) Read a line into an integer. 3) If that integer is greater than the greatest integer, set the greatest to that one. 4) Loop back to step 2. 5) After the end of the loop, print the greatest integer to the screen. It doesn't look like you'll need anything but a main() function for this. The value of GreatestInteger will need to be initialized to the value of the first line. Try that and post your code if you are still having problems. |
|
#3
|
||||
|
||||
Re: I so need help with I/O streamsQuote:
1) Open the file for reading 1a) Read a line into the max integer. This initializes the max integer to one of the numbers in the file, which could be the max 2) Read a line into an integer. 3) If that integer is greater than the greatest integer, set the greatest to that one. 4) Loop back to step 2. 5) After the end of the loop, print the greatest integer to the screen. __________________
The 3 Laws of the Procrastination Society: 1) Never do today that which can be put off until tomorrow 2) Tomorrow never comes |
Recent GIDBlog
Vista ?Widgets? on Windows XP by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| A problem using streams. (I've spent a month trying to solve it) | Mararia | C++ Forum | 8 | 14-Dec-2006 16:52 |
| Menu of character strings | aijazbaig1 | C Programming Language | 21 | 27-Jul-2006 03:07 |
| ??? if no fclose() | balusss | C Programming Language | 3 | 07-Jul-2006 02:48 |
| Reading socket input streams. | AJSHOPE | C++ Forum | 2 | 21-May-2006 16:42 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The