Reputation: 595
I have f.e. "I am working as a nurse." How Can I or which function use to get word from letter number 1 to space or to letter number 11?
So should I get " am working "
Upvotes: 1
Views: 20194
Reputation: 110648
It is not totally clear what you want, but from your example it seems like you want the substring that starts at character 1 and ends on the character 11 places later (that's 12 characters total). That means you want string::substr
:
std::string str("I am working as a nurse");
std::string sub = str.substr(1,12);
Upvotes: 2
Reputation: 1998
char[] source = "I am working as a nurse."
char[11] dest;
strncpy(dest, &source[1], 10)
Upvotes: 0
Reputation: 264331
To read a word from a stream use operator>> on a string
std::stringstream stream("I am working as a nurse.");
std::string word;
stream >> word; // word now holds 'I'
stream >> word; // word now holds 'am'
stream >> word; // word now holds 'working'
// .. etc
Upvotes: 9