How should i go about loading a variable from a string?: for example, this is my text file:
int: 10
int: 25
int: 30
How could i load these into a array? this is the code i use to load the strings:
string loadedB[100];
ifstream loadfile;
loadfile.open("ints.txt");
if(!loadfile.is_open()){
MessageBoxA(0, "Could not open file!","Could not open file!", MB_OK);
return;
}
string line; int i = -1;
while(getline(loadfile, line)){ i++;
loadedB[i] = line;
}
loadfile.close();
for(int x = 0; x < count(loadedB); x++){
cout << loadedB[x] << endl;
}
I would like to do something like:
int intarray[100];
loadfromstringarray(loadedB, intarray);
That code would take the part of the string ( the numeric one ) and would put that value into the array, like intarray[0] = 10;
and so on
EDIT: istringstream is the solution!