fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <cctype>
  5. #include <cstdlib>
  6. #include <fstream>
  7. #include <sstream>
  8.  
  9. struct PersonInfo
  10. {
  11. std::string name;
  12. std::vector<std::string> phones;
  13. PersonInfo() = default;
  14. PersonInfo (std::string &line);
  15. };
  16.  
  17. PersonInfo (std::string &line)
  18. {
  19. std::string word;
  20. std::istringstream ss(line);
  21. ss >> name;
  22. while (ss >> word)
  23. phones.push_back (word);
  24. }
  25.  
  26. int main()
  27. {
  28. std::ifstream in("phones");
  29. std::string line, word;
  30. std::vector<PersonInfo> users;
  31.  
  32. PersonInfo info;
  33. while (getline(in, line))
  34. {
  35. info = line;
  36. users.push_back (info);
  37. }
  38.  
  39. for (const auto &rec: users)
  40. {
  41. std::cout << rec.name << " ";
  42. for (const auto &ph: rec.phones)
  43. std::cout << ph << " ";
  44. std::cout << std::endl;
  45. }
  46. }
  47.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:17:25: error: expected ')' before '&' token
 PersonInfo (std::string &line)
                         ^
stdout
Standard output is empty