you could use the atoi()
function i believe in the header of the std library.
it will convert an ascii string to and integer. so...
#include<string>
string number, word;
std::vector<int> first;
std::vector<string> second;
ifstream inFile(File);
if (inFile.is_open()) {
while (inFile >> number >> word) {
first.push_back(atoi(number));
second.push_back(word);
}
}
You may need to check to make sure that atoi()
did not fail before you push onto the vector but this may work for your situation.
Good Luck
EDIT: based on the comment below stating that atoi()
may be a bad choice i will amend my answer. See this link. It's accepted answer recommends using std::stoi()
so to amend my answer...
#include<string>
string number, word;
std::vector<int> first;
std::vector<string> second;
ifstream inFile(File);
if (inFile.is_open()) {
while (inFile >> number >> word) {
first.push_back(std::stoi(number));//changed this line
second.push_back(word);
}
}