c++ - gcc and clang both cannot compile a loop program -
i've been unable gcc , clang compile simple programme i've written exercise in textbook. objective of programme take 2 simple integer values standard input, , print out 2 values standard output. programme have written follows:
#include<iostream> #include<string> #include<vector> #include<algorithm> #include<cmath> using namespace std; inline void keep_window_open() {char ch; cin>>ch;} int main() { vector<int> vect; int number; int = 0 ; while (cin >> number && vect.size() < 3) { vect.push_back(number); } cout << vect << '\n'; }
when compile programme gcc, next error:
kohs-macbook-pro:learning_c++ kohaugustine$ gcc drill_chapter_4_v2.cpp -o drill_chapter_4_v2 -stdlib=libstdc++ -lstdc++ drill_chapter_4_v2.cpp:21:8: error: invalid operands binary look ('ostream' (aka 'basic_ostream<char>') , 'vector<int>') cout << vect << '\n'; ~~~~ ^ ~~~~
the same error "invalid operands binary expression" happens when seek using clang.
does know problem here?
i'm new c++ , although had experience python, moving c++ different, , i've yet take formal introductory courses in programming, please bear me if simple problem. appreciate help move forward!
thank you!
you can't print entire vector that. utilize loop:
for (auto value : vect) std::cout << value << ' ';
c++ gcc vector clang
No comments:
Post a Comment