fork download
  1. #include <sstream>
  2. #include <string>
  3. #include <vector>
  4. #include <iostream>
  5.  
  6. std::string foo()
  7. {
  8. std::vector<std::string> data;
  9. data.push_back("One");
  10. data.push_back("1");
  11. std::ostringstream strm;
  12. std::string s;
  13. for (size_t i = 0; i < data.size(); ++i)
  14. {
  15. strm << "The " << data[i] << " is number " << i + 1;
  16. s = strm.str();
  17. std::cout << s << "\n";
  18. strm.str("");
  19. }
  20. return s;
  21. }
  22.  
  23. int main()
  24. {
  25. foo();
  26. }
  27.  
Success #stdin #stdout 0s 4500KB
stdin
Standard input is empty
stdout
The One is number 1
The 1 is number 2