fork(1) download
  1. #include fstream;
  2. #include iostream;
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.  
  8.  
  9. ifstream asd("asd.txt");
  10. if(false == asd.is_open())
  11. {
  12. cout << "Can not open input file" << std::endl;
  13.  
  14. return 0 ;
  15. }
  16.  
  17. float val = 0.0f;
  18. string inputString;
  19.  
  20. //We need load on line
  21. getline(asd, inputString);
  22.  
  23. if(true == inputString.empty())
  24. {
  25. cout << "File is empty" << std::endl;
  26.  
  27. return 0 ;
  28. }
  29.  
  30. try
  31. {
  32. val = stof(inputString);
  33. }
  34. catch(exception exp)
  35. {
  36. cout << "Input data is not valid." << std::endl;
  37.  
  38. return 0;
  39. }
  40.  
  41. cout << "Value: " << val << std::endl;
  42.  
  43. system("Pause");
  44. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:10: error: #include expects "FILENAME" or <FILENAME>
 #include fstream;
          ^
prog.cpp:2:10: error: #include expects "FILENAME" or <FILENAME>
 #include iostream;
          ^
prog.cpp: In function 'int main()':
prog.cpp:9:5: error: 'ifstream' was not declared in this scope
     ifstream asd("asd.txt");
     ^
prog.cpp:10:17: error: 'asd' was not declared in this scope
     if(false == asd.is_open())
                 ^
prog.cpp:12:9: error: 'cout' was not declared in this scope
         cout << "Can not open input file" << std::endl;
         ^
prog.cpp:12:46: error: 'endl' is not a member of 'std'
         cout << "Can not open input file" << std::endl;
                                              ^
prog.cpp:18:5: error: 'string' was not declared in this scope
     string inputString;
     ^
prog.cpp:21:13: error: 'asd' was not declared in this scope
     getline(asd, inputString);
             ^
prog.cpp:21:18: error: 'inputString' was not declared in this scope
     getline(asd, inputString);
                  ^
prog.cpp:21:29: error: 'getline' was not declared in this scope
     getline(asd, inputString);
                             ^
prog.cpp:25:9: error: 'cout' was not declared in this scope
         cout << "File is empty" << std::endl;
         ^
prog.cpp:25:36: error: 'endl' is not a member of 'std'
         cout << "File is empty" << std::endl;
                                    ^
prog.cpp:32:31: error: 'stof' was not declared in this scope
         val = stof(inputString);
                               ^
prog.cpp:34:11: error: 'exception' does not name a type
     catch(exception exp)
           ^
prog.cpp:36:9: error: 'cout' was not declared in this scope
         cout << "Input data is not valid." << std::endl;
         ^
prog.cpp:36:47: error: 'endl' is not a member of 'std'
         cout << "Input data is not valid." << std::endl;
                                               ^
prog.cpp:41:5: error: 'cout' was not declared in this scope
     cout << "Value: " << val << std::endl;
     ^
prog.cpp:41:33: error: 'endl' is not a member of 'std'
     cout << "Value: " << val << std::endl;
                                 ^
prog.cpp:43:19: error: 'system' was not declared in this scope
     system("Pause");
                   ^
stdout
Standard output is empty