I have a .txt file looking like this:
1
Some string
Some other string
3
10,5
20
20
I need to read all these values into different type of variables. As far as ints and doubles reading from file seems to be working but then it comes to strings the fun begins.
It seems that strings are read but then I try to output them the whole console just crash.
EDIT:
By “crash” I mean that “Not responding” type of message appears. and the code I use is basically:
ifstream file;
file.open ("C:\path\file.txt");
file >> int1;
getline(file, string1);
getline(file, string2);
file >> int2;
file >> double1;
file >> double2;
file >> double3;
// ....
file.close();
EDIT 2: Somehow instead of 1 value of int1 is -858993460.
I am getting really confused…
EDIT 3: Now all vales are being set but they are not the values written in file.
First int and first srting are fine but second string is red as a 0 and a doubles are all red as
-92559631349317830000000000000000000000000000000000000000000000
Since there are some more values in the file and they accept pattern by type I ran a cycle to get them all the problem is that after first read the values are not red again.
file.open (“C:\path\file.txt”);
\ is escape character
fix
file.open (“C:\\path\\file.txt”);