Search
 
SCRIPT & CODE EXAMPLE
 

CPP

how to iterate in string in c++

#include<iostream>
using namespace std;
main() {
   string my_str = "Hello World";
   for(int i = 0; i<my_str.length(); i++) {
      cout << my_str.at(i) << endl; //get character at position i
   }
}
Comment

cpp iterate words of string

#include <iostream>
#include <sstream>

std::string input = "This is a sentence to read";
std::istringstream ss(input);
std::string token;

while(std::getline(ss, token, ' ')) {
    std::cout << token << endl;
}
Comment

how to iterate throguh a string in c++

void print(const std::string &s)
{
    for (std::string::size_type i = 0; i < s.size(); i++) {
        std::cout << s[i] << ' ';
    }
}
Comment

string iterator in c++

// string::begin/end
#include <iostream>
#include <string>

int main ()
{
  std::string str ("Test string");
  for ( std::string::iterator it=str.begin(); it!=str.end(); ++it)
    std::cout << *it << endl;
  std::cout << '
';

  return 0;
}
Comment

traverse through a string cpp


void print(const std::string &s)
{
    for (std::string::size_type i = 0; i < s.size(); i++) {
        std::cout << s[i] << ' ';
    }
}
Comment

traverse string in cpp

// C++ program to demonstrate getline() function
 
#include <iostream>
#include <string>
using namespace std;
 
int main()
{
    string str;
 
    cout << "Please enter your name: 
";
    getline(cin, str);
    cout << "Hello, " << str
         << " welcome to GfG !
";
 
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: structure and function c++ 
Cpp :: heap buffer overflow c++ 
Cpp :: how to get command arguments c++ 
Cpp :: to_string c++ 
Cpp :: find length of array c++ 
Cpp :: lcm function c++ 
Cpp :: C++ convert vector of digits into integer 
Cpp :: create random vectors c++ 
Cpp :: calling struct to a struct c++ 
Cpp :: c++ switch string 
Cpp :: count word accurances in a string c++ 
Cpp :: input 2d vector c++ 
Cpp :: string to number in c++ 
Cpp :: c++ case 
Cpp :: in c++ the default value of uninitialized array elements is 
Cpp :: c++ construnctor 
Cpp :: bubble sort in c+ 
Cpp :: what is the associative property of an operator 
Cpp :: mkdir c++ 
Cpp :: c++ max of array 
Cpp :: c++ get environment variable 
Cpp :: cpp std list example 
Cpp :: c++ vector extend vector 
Cpp :: binary representation c++ 
Cpp :: what is c++ used for 
Cpp :: how to find the sum of a vector c++ 
Cpp :: for loop c++ 
Cpp :: To Lower Case leetcode solution in c++ 
Cpp :: Reverse Level Order Traversal cpp 
Cpp :: c++ hashmaps 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =