fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. std::string s = "What is the right way to split a string into a vector of strings";
  6. std::stringstream ss(s);
  7. std::istream_iterator<std::string> begin(ss);
  8. std::istream_iterator<std::string> end;
  9. std::vector<std::string> vstrings(begin, end);
  10. std::copy(vstrings.begin(), vstrings.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
  11. return 0;
  12. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:6:23: error: variable ‘std::stringstream ss’ has initializer but incomplete type
 std::stringstream ss(s);
                       ^
prog.cpp:7:1: error: ‘istream_iterator’ is not a member of ‘std’
 std::istream_iterator<std::string> begin(ss);
 ^
prog.cpp:7:34: error: expected primary-expression before ‘>’ token
 std::istream_iterator<std::string> begin(ss);
                                  ^
prog.cpp:7:44: error: ‘begin’ was not declared in this scope
 std::istream_iterator<std::string> begin(ss);
                                            ^
prog.cpp:8:1: error: ‘istream_iterator’ is not a member of ‘std’
 std::istream_iterator<std::string> end;
 ^
prog.cpp:8:34: error: expected primary-expression before ‘>’ token
 std::istream_iterator<std::string> end;
                                  ^
prog.cpp:8:36: error: ‘end’ was not declared in this scope
 std::istream_iterator<std::string> end;
                                    ^
prog.cpp:9:1: error: ‘vector’ is not a member of ‘std’
 std::vector<std::string> vstrings(begin, end);
 ^
prog.cpp:9:24: error: expected primary-expression before ‘>’ token
 std::vector<std::string> vstrings(begin, end);
                        ^
prog.cpp:9:45: error: ‘vstrings’ was not declared in this scope
 std::vector<std::string> vstrings(begin, end);
                                             ^
prog.cpp:10:45: error: ‘ostream_iterator’ is not a member of ‘std’
 std::copy(vstrings.begin(), vstrings.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
                                             ^
prog.cpp:10:78: error: expected primary-expression before ‘>’ token
 std::copy(vstrings.begin(), vstrings.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
                                                                              ^
prog.cpp:10:91: warning: left operand of comma operator has no effect [-Wunused-value]
 std::copy(vstrings.begin(), vstrings.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
                                                                                           ^
stdout
Standard output is empty