fork download
  1. int main()
  2. {
  3. std::ifstream file( "data.txt" ) ;
  4. std::string search_str = "Man" ;
  5. std::string line_1 ;
  6. std::string line_2;
  7. int line_number = 0 ;
  8. while( std::getline( file, line_1 ) )
  9. {
  10. ++line_number ;
  11.  
  12. if( line_1.find(search_str) != std::string::npos )
  13. {
  14. std::cout<<line_1<<'\n';
  15. std::getline(file,line_2);
  16. std::cout<<line_2<<'\n';
  17. }
  18.  
  19. }
  20.  
  21. return (0);
  22. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:3:9: error: ‘ifstream’ is not a member of ‘std’
         std::ifstream file( "data.txt" ) ;
         ^
prog.cpp:3:23: error: expected ‘;’ before ‘file’
         std::ifstream file( "data.txt" ) ;
                       ^
prog.cpp:4:9: error: ‘string’ is not a member of ‘std’
         std::string search_str = "Man" ;
         ^
prog.cpp:4:21: error: expected ‘;’ before ‘search_str’
         std::string search_str = "Man" ;
                     ^
prog.cpp:5:9: error: ‘string’ is not a member of ‘std’
         std::string line_1 ;
         ^
prog.cpp:5:21: error: expected ‘;’ before ‘line_1’
         std::string line_1 ;
                     ^
prog.cpp:6:9: error: ‘string’ is not a member of ‘std’
         std::string line_2;
         ^
prog.cpp:6:21: error: expected ‘;’ before ‘line_2’
         std::string line_2;
                     ^
prog.cpp:8:16: error: ‘getline’ is not a member of ‘std’
         while( std::getline( file, line_1 ) )
                ^
prog.cpp:8:30: error: ‘file’ was not declared in this scope
         while( std::getline( file, line_1 ) )
                              ^
prog.cpp:8:36: error: ‘line_1’ was not declared in this scope
         while( std::getline( file, line_1 ) )
                                    ^
prog.cpp:12:29: error: ‘search_str’ was not declared in this scope
             if( line_1.find(search_str) != std::string::npos )
                             ^
prog.cpp:12:49: error: ‘std::string’ has not been declared
             if( line_1.find(search_str) != std::string::npos )
                                                 ^
prog.cpp:14:17: error: ‘cout’ is not a member of ‘std’
                 std::cout<<line_1<<'\n';
                 ^
prog.cpp:15:17: error: ‘getline’ is not a member of ‘std’
                 std::getline(file,line_2);
                 ^
prog.cpp:15:35: error: ‘line_2’ was not declared in this scope
                 std::getline(file,line_2);
                                   ^
prog.cpp:16:17: error: ‘cout’ is not a member of ‘std’
                 std::cout<<line_2<<'\n';
                 ^
stdout
Standard output is empty