I've been trying to make a program that can read some information from a file and store it in memory to compare with user input. It's sort of a quiz with organic synthesis. A synthesis is dived into steps so I chose to make a synthesis a vector of vector strings. That way every vector inside the main vector is a step and everything inside the step is the reactant and the solvent required for the reaction. As you will see, each synthesis is stored in a text file that has a number for a name. it has a number for a name because that way it is easier to get the level of difficulty of the synthesis.The problem I'm facing is that when I try to read the file that contains the synthesis I get weird formatting errors. Here's the code snippet
int disponible=100; // las sintesis disponibles del 0 al 99 en ese level
ifstream tempsynth;
int SynthNumber;
do {
SynthNumber = rand() % (disponible)+ Level*100;
string filename=itoa(SynthNumber)+".txt";
tempsynth.open(filename.c_str(),ios::binary);
if (!tempsynth)
disponible=disponible-5; //como no van a haber 100 sintesis se baja la busqueda hasta que hallan
}
while (!tempsynth);
getline(tempsynth,Pasosstr);
stringstream(Pasosstr)>>Pasos;
string tempstr;
Paso temp;
temp.clear();
while(tempsynth ){
for (int x=0;x<6;x++){
getline(tempsynth,tempstr);
if (tempstr!="#" && tempstr!="TM\0" && tempstr!="\0" && tempstr!="\n"){
temp.push_back(tempstr);
}
}
Key.push_back(temp);
for (int x=0;x< (int) temp.size();x++)
Log<<"Temp tiene---->"<<temp[x]<<" en la posicion "<<x<<"\n";
temp.clear();
}
The output from the last for loop is this:
Temp tiene---->NAOH
en la posicion 0
Temp tiene---->1EQUI
en la posicion 1
Temp tiene---->*H2O
en la posicion 2
Temp tiene---->#
en la posicion 3
Temp tiene---->KH
en la posicion 4
Temp tiene---->|
en la posicion 5
Temp tiene---->NAOH
en la posicion 0
Temp tiene---->*H2O
en la posicion 1
Temp tiene---->TM
en la posicion 2
Temp tiene---->
en la posicion 3
Temp tiene---->3
en la posicion 4
Temp tiene---->4
en la posicion 5
Temp tiene---->5
en la posicion 0
The file it's reading from has this written on it:
2
NAOH
1EQUI
*H2O
#
KH
|
NAOH
*H2O
TM
3
4
5
#
Anyone know what wrong with this? Why is the line getting eaten up like that?