For a project im working i want to grab text before the space and after the space.
to find the space i use the isspace method, any ideas how to get this done
For a project im working i want to grab text before the space and after the space.
to find the space i use the isspace method, any ideas how to get this done
Like 0x499602D2 noted in the commments, you can use std::stringstream to read from string just as you would do with any other stream (like std::cin):
#include <sstream>
#include <iostream>
#include <string>
int main()
{
int a, b;
std::stringstream ss(std::stringstream::in | std::stringstream::out);
ss << "12 14";
ss >> a;
ss >> b;
std::cout << a << std::endl;
std::cout << b << std::endl;
return 0;
}
Nice thing about this is that if you know how to work with std::cin or any other stream, you know how to work with stringstream, so you can adapt this example for you needs.