Pages

Tuesday, April 22, 2025

String Member Functions in C++

 #include <iostream>

#include <cstring>

using namespace std;


int main()

{

    // string str = "apna college";

    string str = "java, c++ and python & c++ with c++ magic";

    

    // cout << str.length() << endl;

    // cout << str[2] << endl;

    // cout << str.at(2) << endl;

    // cout << str.substr(5, 5) << endl;

    // cout << str.find("c++", 26) << endl;

    

    int idx = str.find("c++");

    cout << idx << endl;


    return 0;

}

No comments:

Post a Comment

remove duplicates from sorted array - two pointer approach (leetcode)

  class Solution {     public int removeDuplicates ( int [] nums ) {         // base case: return if array have no el.         if ( nums...