c++ get char from string code example
Example 1: index string c++
#include <string>
#include <iostream>
int main(){
std::string string = "Hello, World!";
char stringindex = string[2];
}
Example 2: indexing strings in c++
#include <iostream>
#include <string>
int main ()
{
std::string str ("Test string");
for (int i=0; i<str.length(); ++i)
{
std::cout << str[i];
}
return 0;
}
Example 3: c++ get character from string
#include <iostream>
#include <string>
int main() {
std::string myStr = "test string";
for (int i = 0; i < myStr.length(); ++i) {
std::cout << myStr.at(i) << std::endl;
}
return 0;
}