I'm trying to read all the lines of a given file.
For some reason, std::getline
doesn't work as expected.
main.cpp:
#include <iostream>
#include <fstream>
#include <string>
int main() {
std::string filePath = "../init.txt";
std::ifstream inputFile(filePath);
std::string str;
int i = 0;
while (std::getline(inputFile,str)) {
std::cout << str << std::endl;
i++;
}
std::cout << i << std::endl;
inputFile.close();
return 0;
}
../init.txt:
Game
battlefieldSize,100,200
players,2
soldiers,3
p1,human
normal,[2 3],M16
paramedic,[10 31]
sniper,[5 12],UZI
p2,computer,0
normal,[90 112],Missile
sniper,[90 113],M16
normal,[65 100],M16
Objects
weapon,M16,[5 5]
Armor,BodyArmor,0.8,[1 2]
weapon,Missile,[15 115]
solid,Tree,4,4,[20 20]
As you can see, I wanted to know how much times it's entering the loop, with variable i
. The output is:
solid,Tree,4,4,[20 20]
1
Why is that happening?