Answers for "c++ string element access"

C++
4

index string c++

#include <string>
#include <iostream>

int main(){
  //index string by using brackets []
  std::string string = "Hello, World!";
  //assign variable to string index
  char stringindex = string[2];
  
}
Posted by: Guest on June-15-2020
2

c++ string element access

// string::operator[]
#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;
}
Posted by: Guest on July-20-2020
-1

how to access the element of string in c++

string myString = "Hello";
cout << myString[0];
// Outputs H
Posted by: Guest on November-06-2020

Browse Popular Code Answers by Language