Answers for "string.substr c"

C++
16

c++ substring

// string::substr
#include <iostream>
#include <string>

int main ()
{
  std::string str="We think in generalities, but we live in details.";
                                           // (quoting Alfred N. Whitehead)

  std::string str2 = str.substr (3,5);     // "think"

  std::size_t pos = str.find("live");      // position of "live" in str

  std::string str3 = str.substr (pos);     // get from "live" to the end

  std::cout << str2 << ' ' << str3 << 'n';

  return 0;
}
Posted by: Guest on March-23-2020
4

c substring

char subbuff[5];
memcpy( subbuff, &buff[10], 4 );
subbuff[4] = '';
Posted by: Guest on March-19-2020
2

c substring

//where we want the word "test" and we know its position in the string
char *buff = "this is a test string";
printf("%.*s", 4, buff + 10);
Posted by: Guest on June-21-2020

Browse Popular Code Answers by Language