12345678910111213141516171819
#include <iostream> #include <sstream> #include <string> using namespace std; void getXYZ( const string &str, int &x, int &y, int &z ) { char comma; stringstream( str ) >> x >> comma >> y >> comma >> z; } int main() { int x, y, z; string test = "1, 10, 100"; getXYZ( test, x, y, z ); cout << "x: " << x << " y: " << y << " z: " << z << '\n'; }
x: 1 y: 10 z: 100