string manipulation

Hello, I am trying to manipulate a string (below). How would I put "John" in a seperate string, 1 in an int, 2 in an int, and 3 in a double? I figured out how to get John from it.

1
2
3
4
5
6
7
8
string s = "John 1 2 3";

string name = s.substr(0, s.find(' ')); 
//below are my lame attempts to get the rest
string wins = user.substr(playerOne.username.length(), user.find(' '));
string losses = user.substr(wins.length(), user.find(' '));
string winLossRatio = user.substr(losses.length(), user.find(' '));
Last edited on
1
2
3
4
5
std::istringstream input(s); //#include <sstream>
std::string name;
int wins, losses;
double winLossRatio;
input >> name >> wins >> losses >> winLossRatio;
Topic archived. No new replies allowed.