Answer the question
In order to leave comments, you need to log in
Splitting string into 2 parts and converting to int?
for (int i = 1; i <= k; i++) {
getline(file, text);
cout << "1 part '" << text.substr(0, text.find('/')) << "' sec part '" << text.substr(text.find('/') + 1)<<"'" << endl;
day += stoi(text.substr(0,text.find("/")).c_str())- 48 + stoi (text.substr(text.find("/")+1).c_str()) - 48;
cout << "day " << day << endl;
}
Answer the question
In order to leave comments, you need to log in
in general like this:
std::string str = "00/34";
std::string::size_type slash = str.find("/");
if (slash != std::string::npos) {
int num1 = atoi(str.substr(0, slash-1).c_str());
int num2 = atoi(str.substr(slash+1).c_str());
cout<<"Num1: " << num1 << ", Num2: " << num2;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question