Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
hoklavat committed Feb 3, 2021
1 parent 167bcc3 commit 1f0b776
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions 53-RangedFor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//53-RangedFor

#include <iostream>
#include <cstring>
#include <algorithm>

class A{
private:
char* s;
int size;
public:
A(const char* t){
size = strlen(t);
s = new char(size);
strcpy(s, t);
}

void print(){
std::cout << s << std::endl;
}

friend char* begin(A& x);
friend char* end(A& x);
};

char* begin(A& x){
return x.s;
}

char* end(A& x){
return x.s+x.size;
}

int main(){
A a{"Hello World!"};
a.print();

for(auto c: a)
std::cout << c;
std::cout << std::endl;

std::for_each(begin(a), end(a), [](char c){std::cout << c;});
std::cout << std::endl;
}

0 comments on commit 1f0b776

Please sign in to comment.