I am trying to convert a string of numbers to an integer array. Each number is a single digit so I should be able to just iterate over the characters and store them to an array. The code I have so far is:
I was thinking I would use stringstream to convert it but I can only get it to convert a string to a single integer, so I would recieve 123456 for example, but I want 1,2,3,4,5,6.
You could read one character at a time into the stringstream (using string::at()), then output the resulting integer from the stringstream into your vector.
#include <iostream> // Standard input and output
#include <fstream> // Reading to and from files
#include <vector> // Allows for dynamic array resizing
#include <string> // Allows for reading from the savefile
#include <sstream> // Allows for processing the savefile string into a vector
usingnamespace std;
int main()
{
string stringSaveFileData;
fstream saveFile ("save.txt", fstream::in | fstream::out);
getline(saveFile, stringSaveFileData);
saveFile.close();
stringstream convert;
vector<int> numericSaveFileData;
for (unsignedint i=0; i < stringSaveFileData.length(); i++)
{
numericSaveFileData[i] << convert(stringSaveFileData.at(i));
}
}