fork(1) download
  1. #include<iostream>
  2. #include<string>
  3.  
  4. using namespace std;
  5.  
  6.  
  7.  
  8. struct car{
  9. int weight;
  10. string color;
  11. };
  12.  
  13. int main()
  14. {
  15. car car1={100, "red"};
  16. car car2={200, "blue"};
  17. car car3={300, "green"};
  18.  
  19. car * pc1;
  20. pc1=&car1;
  21. cout<<pc1<<endl;
  22. cout<<&pc1<<endl;
  23. cout<<*pc1<<endl<<endl;
  24. cout<<(*pc1).weight<<" "<<pc1->color<<endl;
  25. cout<<(*pc2).weight<<" "<<pc2->color<<endl;
  26. cout<<(*pc3).weight<<" "<<pc3->color<<endl;
  27.  
  28.  
  29.  
  30. return 0;
  31. }
  32.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:23:8: error: cannot bind ‘std::ostream {aka std::basic_ostream<char>}’ lvalue to ‘std::basic_ostream<char>&&’
 cout<<*pc1<<endl<<endl;
        ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from prog.cpp:1:
/usr/include/c++/4.8/ostream:602:5: error:   initializing argument 1 of ‘std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&&, const _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Tp = car]’
     operator<<(basic_ostream<_CharT, _Traits>&& __os, const _Tp& __x)
     ^
prog.cpp:25:9: error: ‘pc2’ was not declared in this scope
 cout<<(*pc2).weight<<" "<<pc2->color<<endl;
         ^
prog.cpp:26:9: error: ‘pc3’ was not declared in this scope
 cout<<(*pc3).weight<<" "<<pc3->color<<endl;
         ^
stdout
Standard output is empty