| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am new to C++ and am trying to read the amount of numbers in a file and count them using a counter-controlled for loop. Can anyone help me. I know how to open up the file, but dont know what to do next.
|
|
#2
|
|||
|
|||
|
ifstream fin; //infile.
int number; fin>>number;//reads in a single number(not a single character) //presuming the first number in the file tells you how many numbers are to come in the file, just use a for or while loop to read in the rest of the numbers and add them as you go along. While loop is probably best so you can include a !fin.eof() statement to abort the loop if you reach the end of the file before the requested number are read. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > C++ a little help? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|