Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

how to traverse string like array in cpp

// C++ program to implement
// the above approach
  
#include <bits/stdc++.h>
using namespace std;
  
// Function to traverse the string and
// print the characters of the string
void TraverseString(string &str, int N)
{ 
    // Traverse the string
    for (int i = 0; i < N; i++) {
  
        // Print current character
        cout<< str[i]<< " ";
    }
      
}
  
// Driver Code
int main()
{
    string str = "GeeksforGeeks";
      
    // Stores length of the string
    int N = str.length();
  
    TraverseString(str, N);
}
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #traverse #string #array #cpp
ADD COMMENT
Topic
Name
2+2 =