fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <sstream>
  5.  
  6. using namespace std;
  7.  
  8. void getIdFromFile (string filename, istream &is, ostream &os)
  9. {
  10. string name, n;
  11. int id(0);
  12. while(is >> n)
  13. {
  14. //ifstream ifs(filename);
  15. stringstream ifs("sclaus 12 jblack 779 jbanno 334");
  16. while(ifs >> name && ifs >> id && n != name)
  17. {
  18. id = 0;
  19. }
  20. if(id == 0)
  21. cout << "ERROR" << endl;
  22. else
  23. cout << "ID= " << id << endl;
  24. //return id;
  25. }
  26. }
  27. int main() {
  28. /*int id =*/ getIdFromFile("", cin, cout);
  29. }
Success #stdin #stdout 0s 3480KB
stdin
jblack
sclaus
frank
stdout
ID= 779
ID= 12
ERROR