# ios has not been declared (C++)



## Nyap (Jul 9, 2016)

```
#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()};
}
```



> ||=== Build: Debug in Voweltest (compiler: GNU GCC Compiler) ===|
> /media/nyap/acb384f6-b8a7-482b-b700-4070bd5c283b/learncpp/Voweltest/main.cpp||In function ‘int main()’:|
> /media/nyap/acb384f6-b8a7-482b-b700-4070bd5c283b/learncpp/Voweltest/main.cpp|10|error: ‘ios’ has not been declared|
> /media/nyap/acb384f6-b8a7-482b-b700-4070bd5c283b/learncpp/Voweltest/main.cpp|16|error: ‘ios’ has not been declared|
> ...


wtf


----------



## Tenshi_Okami (Jul 9, 2016)

Nyap said:


> ```
> #include <iostream>
> #include <fstream>
> #include <cstdlib>
> ...


Ok so i barely know something from C++(Started to learn Yesterday) but have you declared what IOS is used for?


----------



## Nyap (Jul 9, 2016)

what
Idk what you mean


----------



## Tenshi_Okami (Jul 9, 2016)

Spoiler: One of the compile errors



error: ‘ios’ has not been declared


----------



## Nyap (Jul 9, 2016)

ios is a class which ifstream is derived from (I think, I can't remember)

edit: yup pretty sure now


----------



## Tenshi_Okami (Jul 9, 2016)

```
#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


Spoiler: error



C:\Users\Angel\Documents\New folder\random\main.cpp|12|error: 'input' was not declared in this scope|


Like i said, i barely know C++ ;-;


----------



## Nyap (Jul 9, 2016)

Tenshi_Okami said:


> ```
> #include <iostream>
> #include <fstream>
> #include <cstdlib>
> ...


that shouldn't work O_O
try compiling it on yours without the int ios and let me know if anything changes


----------



## Tenshi_Okami (Jul 9, 2016)

Spoiler: lol



||=== Build: Debug in random (compiler: GNU GCC Compiler) ===|
C:\Users\Angel\Documents\New folder\random\main.cpp||In function 'int main()':|
C:\Users\Angel\Documents\New folder\random\main.cpp|10|error: 'ios' has not been declared|
C:\Users\Angel\Documents\New folder\random\main.cpp|16|error: 'ios' has not been declared|
C:\Users\Angel\Documents\New folder\random\main.cpp|17|warning: extended initializer lists only available with -std=c++11 or -std=gnu++11|
C:\Users\Angel\Documents\New folder\random\main.cpp|17|warning: unused variable 'count_limit' [-Wunused-variable]|
||=== Build failed: 2 error(s), 2 warning(s) (0 minute(s), 0 second(s)) ===|


Same thing as your error lol


----------



## Nyap (Jul 9, 2016)

._. ill try updating gcc and see if that makes a difference


----------



## Flyingsky (Jul 9, 2016)

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.


----------



## Tenshi_Okami (Jul 9, 2016)

wait no im dumd xD ignore this


----------



## Nyap (Jul 9, 2016)

Flyingsky said:


> 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.


what sort of error

--------------------- MERGED ---------------------------



Tenshi_Okami said:


> I found how to fix the ios error
> 
> 
> ```
> ...


I already tried that earlier - I get this


> /media/nyap/acb384f6-b8a7-482b-b700-4070bd5c283b/learncpp/Voweltest/main.cpp|10|error: ‘nocreate’ is not a member of ‘std::ios {aka std::basic_ios<char>}’|


also, I just upgraded to g++6. No difference


----------



## Flyingsky (Jul 9, 2016)

You can see that error with something like:


```
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:
	
	



```
int length = input.tellg();
```


----------



## Nyap (Jul 9, 2016)

Flyingsky said:


> You can see that error with something like:
> 
> 
> ```
> ...


ok, so it's not the program crashing kind of error, just failbit, right?
and whats perror?


----------



## Flyingsky (Jul 9, 2016)

this is what perror does:


----------



## Nyap (Jul 9, 2016)

ah ok


----------



## Flyingsky (Jul 9, 2016)

I would write it like that:


```
#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


----------

