I have a text document which looks something like this:
user_name1 1.575
user_name2 3.636
user_name3 2.647
user_name4 5.532
user_name5 4.253
What i am trying to do is, to get these numbers from .txt file into console and save them as variables. I know how to read .txt file in console and I found some answers here how to get each line separately as strings, but i can't get these doubles. Is there some kind of function or whatsoever that goes through strings and finds numbers?
I tried with this:
1) get string of each line 2) loop through them and check ASCII code and if it is a number I saved next 3 or 4 charachters
But its not working very well. Thanks for your help in advance.
EDIT:
string line;
ifstream banka ("banka.txt");
double numbers[5];
if(banka.is_open()) {
for(int i=0; i<5; i++) {
getline(cin,line);
size_t space=line.find(' ');
string numStr=line.substr(space+1);
double num = stod(numStr);
numbers[i]=num;
}
banka.close();
}
else {
cout<<"Unable to open file."<<endl;
}