1

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 "

David G
  • 90,891
  • 40
  • 158
  • 247
Marcin Kostrzewa
  • 545
  • 4
  • 11
  • 24

3 Answers3

8

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
Martin York
  • 246,832
  • 83
  • 321
  • 542
2

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);
Joseph Mansfield
  • 104,685
  • 19
  • 232
  • 315
0
char[] source = "I am working as a nurse."
char[11] dest;
strncpy(dest, &source[1], 10)
tletnes
  • 1,908
  • 10
  • 29