jeudi 27 avril 2017

How to open a file in C++ and read it

I'm trying to open up a file in c++ and I understand that I need to #include , but I don't know what to do in main. What I want to do is to read the file line by line. I can't make it a stream because the lines I'm reading are numbers.

5000
2015
5000
8200
9012
4018
2016
1017
3015
2017
1016
9003
1017
6000
7000
0
0
0
1

These are the numbers that are inside the file. I want to read it line be line. I know I probably need to do a while statement in order for this to work, but I also want to put if else statements inside the while loop. Because I need to take the first number of each line. (Example 5000 is 5, 2015 is 2) I'd like to accomplish that by doing division with integers because it'll just get me the whole number. Basically the biggest question I have is what am I missing to read each line without making them strings.

Aucun commentaire:

Enregistrer un commentaire