ios has not been declared (C++)

Discussion in 'Computer Programming, Emulation, and Game Modding' started by Nyap, Jul 9, 2016.

  1. Nyap
    OP

    Nyap HTML Noob

    Banned
    973
    344
    Jan 13, 2016
    That Chaos Site
    Code:
    #include <iostream>
    #include <fstream>
    #include <cstdlib>
    
    using std::ifstream;
    using std::cout;
    
    int main()
    {
      ifstream input("input.txt", ios::nocreate);
      if (!input.is_open())
      {
      cout << "No input.txt found!\n";
      exit(0);
      }
      input.seekg(0, ios::end);
      int count_limit{input.tellg()};
    }
    
    wtf
     
  2. Tenshi_Okami

    Tenshi_Okami GBAtemp Maniac

    Member
    1,376
    564
    Nov 3, 2015
    Puerto Rico
    Ok so i barely know something from C++(Started to learn Yesterday) but have you declared what IOS is used for?
     
  3. Nyap
    OP

    Nyap HTML Noob

    Banned
    973
    344
    Jan 13, 2016
    That Chaos Site
    what
    Idk what you mean
     
  4. Tenshi_Okami

    Tenshi_Okami GBAtemp Maniac

    Member
    1,376
    564
    Nov 3, 2015
    Puerto Rico
    One of the compile errors
     
  5. Nyap
    OP

    Nyap HTML Noob

    Banned
    973
    344
    Jan 13, 2016
    That Chaos Site
    ios is a class which ifstream is derived from (I think, I can't remember)

    edit: yup pretty sure now
     
    Last edited by Nyap, Jul 9, 2016
  6. Tenshi_Okami

    Tenshi_Okami GBAtemp Maniac

    Member
    1,376
    564
    Nov 3, 2015
    Puerto Rico
    Code:
    #include <iostream>
    #include <fstream>
    #include <cstdlib>
    
    using std::ifstream;
    using std::cout;
    
    int main()
    {
      int ios
      ifstream input("input.txt", ios::nocreate);
      if (!input.is_open())
      {
      cout << "No input.txt found!\n";
      exit(0);
      }
      input.seekg(0, ios::end);
      int count_limit{input.tellg()};
    }
    This seems to fix the IOS error, but then it gives me this
    error
    Like i said, i barely know C++ ;-;
     
    Last edited by Tenshi_Okami, Jul 9, 2016 - Reason: Changed something in the error
  7. Nyap
    OP

    Nyap HTML Noob

    Banned
    973
    344
    Jan 13, 2016
    That Chaos Site
    that shouldn't work O_O
    try compiling it on yours without the int ios and let me know if anything changes
     
  8. Tenshi_Okami

    Tenshi_Okami GBAtemp Maniac

    Member
    1,376
    564
    Nov 3, 2015
    Puerto Rico
    lol
    Same thing as your error lol
     
  9. Nyap
    OP

    Nyap HTML Noob

    Banned
    973
    344
    Jan 13, 2016
    That Chaos Site
    ._. ill try updating gcc and see if that makes a difference
     
  10. Flyingsky

    Flyingsky Advanced Member

    Newcomer
    57
    19
    Apr 8, 2016
    Gambia, The
    I don't think nocreate is even neccesary, because you have an ifstream.
    An ifstream doesn't create a file if it's not there, it just tries to open it and throws an error if there is no file.
     
  11. Tenshi_Okami

    Tenshi_Okami GBAtemp Maniac

    Member
    1,376
    564
    Nov 3, 2015
    Puerto Rico
    wait no im dumd xD ignore this
     
    Last edited by Tenshi_Okami, Jul 9, 2016
  12. Nyap
    OP

    Nyap HTML Noob

    Banned
    973
    344
    Jan 13, 2016
    That Chaos Site
    what sort of error

    — Posts automatically merged - Please don't double post! —

    I already tried that earlier - I get this
    also, I just upgraded to g++6. No difference
     
    Last edited by Nyap, Jul 9, 2016
  13. Flyingsky

    Flyingsky Advanced Member

    Newcomer
    57
    19
    Apr 8, 2016
    Gambia, The
    You can see that error with something like:

    Code:
        ifstream input;
            input.open(file);
    
            if (input.fail())
            {
                perror(file.c_str());
                cout << endl;
            }
    
    It will just say there is no file, if your program runs.

    Oh and for the count limit, you may do something like:
    Code:
    	int length = input.tellg();
     
    Last edited by Flyingsky, Jul 9, 2016
  14. Nyap
    OP

    Nyap HTML Noob

    Banned
    973
    344
    Jan 13, 2016
    That Chaos Site
    ok, so it's not the program crashing kind of error, just failbit, right?
    and whats perror?
     
  15. Flyingsky

    Flyingsky Advanced Member

    Newcomer
    57
    19
    Apr 8, 2016
    Gambia, The
    this is what perror does: [​IMG]
     
  16. Nyap
    OP

    Nyap HTML Noob

    Banned
    973
    344
    Jan 13, 2016
    That Chaos Site
    ah ok
     
  17. Flyingsky

    Flyingsky Advanced Member

    Newcomer
    57
    19
    Apr 8, 2016
    Gambia, The
    I would write it like that:

    Code:
    #include <iostream>
    #include <fstream>
    #include <cstdlib>
    
    
    using namespace std;
    
    int main()
    {
        ifstream input("input.txt");
        if (input.fail())
        {
            cout << "No input.txt found!\n";
            exit(1);
        }
        input.seekg(0, ios_base::end);
        int count_limit = input.tellg();
        cout << count_limit;
    }
    
    That should run
     
    Tenshi_Okami likes this.