ios has not been declared (C++)

  • Thread starter Thread starter Nyap
  • Start date Start date
  • Views Views 9,901
  • Replies Replies 16

Nyap

HTML Noob
Banned
Joined
Jan 13, 2016
Messages
971
Reaction score
347
Trophies
0
Age
57
Location
That Chaos Site
XP
529
Country
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()};
}
||=== 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|
/media/nyap/acb384f6-b8a7-482b-b700-4070bd5c283b/learncpp/Voweltest/main.cpp|17|warning: unused variable ‘count_limit’ [-Wunused-variable]|
||=== Build failed: 2 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|
wtf
 
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
Ok so i barely know something from C++(Started to learn Yesterday) but have you declared what IOS is used for?
 
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
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++ ;-;
 
Last edited by Tenshi_Okami, , Reason: Changed something in the error
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
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++ ;-;
that shouldn't work O_O
try compiling it on yours without the int ios and let me know if anything changes
 
||=== 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
 
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.
 
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 ---------------------------

I found how to fix the ios error

Code:
#include <iostream>
#include <fstream>
#include <cstdlib>

using std::ifstream;
using std::cout;

int main()
{
  ifstream input("input.txt", std::ios::nocreate);
  if (!input.is_open())
  {
  cout << "No input.txt found!\n";
  exit(0);
  }
  input.seekg(0, std::ios::end);
  int count_limit{input.tellg()};
}

Now it only ask to fix the limit in int count_limit

idk why std:: fixed it but lol
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
 
Last edited by Nyap,
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,
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.
ok, so it's not the program crashing kind of error, just failbit, right?
and whats perror?
 
this is what perror does:
36713d5c63.png
 
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
 
  • Like
Reactions: Tenshi_Okami

Site & Scene News

Popular threads in this forum