c++ - Return value of overloaded << -


#include <iostream>  using namespace std;  struct info {     info(int x, int y) : x(x), y(y) {}     int x;     int y; };  ostream& operator<<(ostream& out, const info &myinfo){     out << myinfo.x << "  " << myinfo.y;     return cout; }  int main() {     info a(1,2);     info b(3,4);     cout << << " " << b << endl; } 

the output of above program seems fine incorrect overload of operator <<.

can tell me effect of overloading problem? know overloading function should return out instead of cout, how above version behave?

in case, since passing in std::cout overloaded operator<<, there no difference in behavior. generally, though, cause " " << b << std::endl sent std:cout, while a go whatever passed in.

for example:

info a(1,2); info b(3,4); std::ostringstream ss; ss << << " " << b << std::endl; 

would cause a go ss.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -