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
  • 94,763
  • 41
  • 167
  • 253
Marcin Kostrzewa
  • 565
  • 4
  • 11
  • 24

3 Answers3

9

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
  • 257,169
  • 86
  • 333
  • 562
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
  • 108,238
  • 20
  • 242
  • 324
0
char[] source = "I am working as a nurse."
char[11] dest;
strncpy(dest, &source[1], 10)
tletnes
  • 1,958
  • 10
  • 30