fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4.  
  5. int main()
  6. {
  7. std::istringstream stm( "track1|song1|artist1|album1|\n"
  8. "track2|song2|artist2|album2|\n"
  9. "track3|song3|artist3|album3|\n"
  10. "track4|song4|artist4|album4|\n" ) ;
  11.  
  12. std::string track ;
  13. std::string song ;
  14. std::string artist ;
  15. std::string album ;
  16. constexpr char delimiter = '|' ;
  17.  
  18. while( std::getline( stm, track, delimiter) &&
  19. std::getline( stm, song, delimiter) &&
  20. std::getline( stm, artist, delimiter) &&
  21. std::getline( stm, album, delimiter) &&
  22. stm.ignore( 1000, '\n' ) )
  23. {
  24. std::cout << "track: " << track << "\nsong: " << song
  25. << "\nartist: " << artist << "\nalbum: " << album << "\n\n" ;
  26. }
  27. }
  28.  
Success #stdin #stdout 0s 2984KB
stdin
Standard input is empty
stdout
track: track1
song: song1
artist: artist1
album: album1

track: track2
song: song2
artist: artist2
album: album2

track: track3
song: song3
artist: artist3
album: album3

track: track4
song: song4
artist: artist4
album: album4