extract characters from string c++ code example
Example 1: index string c++
#include <string>
#include <iostream>
int main(){
std::string string = "Hello, World!";
char stringindex = string[2];
}
Example 2: substr c++
#include <iostream>
#include <string>
int main ()
{
std::string str="We think in generalities, but we live in details.";
std::string str2 = str.substr (3,5);
std::size_t pos = str.find("live");
std::string str3 = str.substr (pos);
std::cout << str2 << ' ' << str3 << '\n';
return 0;
}