ios has not been declared (C++)

Nyap

HTML Noob
OP
Banned
Joined
Jan 13, 2016
Messages
971
Trophies
0
Age
55
Location
That Chaos Site
XP
483
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
 

Tenshi_Okami

Well-Known Member
Member
Joined
Nov 3, 2015
Messages
1,490
Trophies
0
Age
25
XP
1,616
Country
Puerto Rico
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?
 

Tenshi_Okami

Well-Known Member
Member
Joined
Nov 3, 2015
Messages
1,490
Trophies
0
Age
25
XP
1,616
Country
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
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

Nyap

HTML Noob
OP
Banned
Joined
Jan 13, 2016
Messages
971
Trophies
0
Age
55
Location
That Chaos Site
XP
483
Country
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
 

Tenshi_Okami

Well-Known Member
Member
Joined
Nov 3, 2015
Messages
1,490
Trophies
0
Age
25
XP
1,616
Country
Puerto Rico
||=== 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
 

Flyingsky

Well-Known Member
Newcomer
Joined
Apr 8, 2016
Messages
57
Trophies
0
XP
130
Country
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.
 

Nyap

HTML Noob
OP
Banned
Joined
Jan 13, 2016
Messages
971
Trophies
0
Age
55
Location
That Chaos Site
XP
483
Country
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,

Flyingsky

Well-Known Member
Newcomer
Joined
Apr 8, 2016
Messages
57
Trophies
0
XP
130
Country
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,

Nyap

HTML Noob
OP
Banned
Joined
Jan 13, 2016
Messages
971
Trophies
0
Age
55
Location
That Chaos Site
XP
483
Country
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?
 

Flyingsky

Well-Known Member
Newcomer
Joined
Apr 8, 2016
Messages
57
Trophies
0
XP
130
Country
Gambia, The
this is what perror does:
36713d5c63.png
 

Flyingsky

Well-Known Member
Newcomer
Joined
Apr 8, 2016
Messages
57
Trophies
0
XP
130
Country
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
 
  • Like
Reactions: Tenshi_Okami

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • BakerMan
    I rather enjoy a life of taking it easy. I haven't reached that life yet though.
  • BigOnYa @ BigOnYa:
    I don't trust the free ones, but ipvanish I've used for couple years now, n like
  • Psionic Roshambo @ Psionic Roshambo:
    I wonder if they could get CPUs to run that hot then use the heat to power a steam turbine to power the CPUs....
  • BigOnYa @ BigOnYa:
    Good idea, or at least power the GPU
  • Psionic Roshambo @ Psionic Roshambo:
    It's not the movies or games downloads that I would worry about, like breaking into networks, downloading encrypted things, spying on network traffic. I have seen so many "Top Secret" seals on files when I was a kid
  • Psionic Roshambo @ Psionic Roshambo:
    I was obsessed with finding UFOs, a surprising amount of US files where stashed on computers in other countries, China back in the early 90s omg sooo much
  • BigOnYa @ BigOnYa:
    Yea that crazy, I've never tried hack into anything, I just pirate, and my ISP have send me 3-4 letters, so had to VPN it
  • Psionic Roshambo @ Psionic Roshambo:
    Ship to ship communication software for the Navy although without access to the encrypting chips it was mostly useless
  • Psionic Roshambo @ Psionic Roshambo:
    I bet now a 4090 could probably crack it? Hmmm maybe not even back then I'm pretty sure they where using like 1024 bit encryption
  • Psionic Roshambo @ Psionic Roshambo:
    Yayyy the one set finished 324GBs lol
  • Psionic Roshambo @ Psionic Roshambo:
    Compressed....
  • Psionic Roshambo @ Psionic Roshambo:
    I wonder how many years that would have taken on a 56K modem lol
  • Psionic Roshambo @ Psionic Roshambo:
    18000 hours lol
  • Psionic Roshambo @ Psionic Roshambo:
    750 days lol
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    So Internet is very much faster now lol
  • BigOnYa @ BigOnYa:
    "Time Remaining- 2 years, 9 girlfriends, 6 hairstyles, please standby..."
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    I remember one time I downloaded like a 500MB ISO file on 56K and that literally took like 2 days
  • Psionic Roshambo @ Psionic Roshambo:
    I had some sort of resume thing, I remember the software had chains
  • Psionic Roshambo @ Psionic Roshambo:
    Damned if I can't remember.the name though
  • Psionic Roshambo @ Psionic Roshambo:
    Some sort of download management app
  • BigOnYa @ BigOnYa:
    Ok good chatting, I'm off to the bar, to shoot some pool, nighty night.
    +1
  • BakerMan @ BakerMan:
    hey psi
  • BakerMan @ BakerMan:
    i call your girl lyndon the way she b on my johnson
    BakerMan @ BakerMan: i call your girl lyndon the way she b on my johnson