charat in 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: c++ string element access
#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++ char define
char YourVar[] = {'H','e','l','l','o','\0'};
Example 4: c++ declare char
char YourVar[] = "Hello!";
Example 5: stoi in c++
stoi()
Example 6: how to access the element of string in c++
string myString = "Hello";
cout << myString[0];