Horje
Iterator in c++ Code Example
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 << '\n';

  return 0;
}
Iterator in c++
//Iterator Pointer like Structore in c++ of STL
#include <bits/stdc++.h>
using namespace std;

int main(){
    vector<int> v = {1,2,3,4,5};
    for(int i = 0; i<v.size(); i++){
        cout<<v[i]<<" ";
    }
    cout<<endl;

    vector<int> :: iterator it;
    // it = v.begin();
    // cout<<(*it+1)<<endl;

    for(it = v.begin(); it !=v.end(); ++it){
        cout<<(*it)<<endl;
    }
    cout<<endl;

    vector<pair<int, int>> v_p = {{1,2},{3,4},{5,6}};
    vector<pair<int ,int>> :: iterator iter;
    for(iter = v_p.begin(); iter !=v_p.end(); ++iter){
        cout<<(*iter).first<<" "<<(*iter).second<<endl;
    }
    cout<<endl;
    for(iter = v_p.begin(); iter !=v_p.end(); ++iter){
        cout<<(iter->first)<<" "<<(iter->second)<<endl;
    }

    return 0;
}
iterator on std::tuple
#include <tuple>
#include <iostream>
#include <boost/hana.hpp>
#include <boost/hana/ext/std/tuple.hpp>

struct Foo1 {
    int foo() const { return 42; }
};

struct Foo2 {
    int bar = 0;
    int foo() { bar = 24; return bar; }
};

int main() {
    using namespace std;
    using boost::hana::for_each;

    Foo1 foo1;
    Foo2 foo2;

    for_each(tie(foo1, foo2), [](auto &foo) {
        cout << foo.foo() << endl;
    });

    cout << "foo2.bar after mutation: " << foo2.bar << endl;
}




Cpp

Related
intersection between vector c++ Code Example intersection between vector c++ Code Example
c++ count vector elements Code Example c++ count vector elements Code Example
transformer in nlp Code Example transformer in nlp Code Example
circular array Code Example circular array Code Example
string c++ Code Example string c++ Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
11