fork download
  1. #include <iostream>
  2. #include <limits>
  3. #include <sstream>
  4. #include <string>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. struct Type {
  10. string line;
  11. int index;
  12. };
  13.  
  14. int main() {
  15. istringstream f("key = -2\nkey = -1\nkey = 0\nÄèîpg\nkey = 2");
  16. string line;
  17. int lineNumber = 0;
  18. const auto line1 = 20;
  19. const auto line2 = 6;
  20. size_t pos;
  21. vector<Type> linesVector;
  22.  
  23. if (f.good()){
  24. while (getline(f, line)) {
  25. lineNumber++;
  26. if ((lineNumber>= line1 - 20) && (lineNumber<= line2)){
  27. pos = line.find("key = 0");
  28. if (pos != string::npos){
  29. if(!f.ignore(numeric_limits<std::streamsize>::max(), '\n')) {
  30. break;
  31. }
  32. ++lineNumber;
  33. std::cout << "skip the line" << endl;
  34. }
  35. else{
  36. Type v;
  37. v.line= line;
  38. v.index = lineNumber;
  39. linesVector.push_back(v);
  40. }
  41. }
  42. }
  43. }
  44.  
  45. for(const auto& i : linesVector) cout << i.index << ": " << i.line << endl;
  46. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
skip the line
1: key = -2
2: key = -1
5: key = 2