473,698 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ifstream on gcc 3.2 problem, simple question

Greetings All,

I think everybodyknows the answer already. But i
am quite a newbie in c++.

I've got the following line in my code:

ifstream ini_file_in("fi lename.dat", ios::in);

But, the gcc (GCC) 3.2 spits out some stuff about
deprecated headers:

user@machine:~/prog/src> gcc -Wall extract_data.cp p
In file included from
/usr/include/g++/backward/fstream.h:31,
from extract_data.cp p:3:
/usr/include/g++/backward/backward_warnin g.h:32:2:
warning: #warning This file includes at least one
deprecated or antiquated header. Please consider
using one of the 32 headers found in section
17.4.1.2 of the C++ standard. Examples include
substituting the <X> header for the <X.h> header
for C++ includes, or <sstream> instead of the
deprecated header <strstream.h> . To disable this
warning use -Wno-deprecated.
extract_data.cp p: In function `int main()':
extract_data.cp p:9: `ios' undeclared (first use
this function)
extract_data.cp p:9: (Each undeclared identifier is
reported only once for each
function it appears in.)
extract_data.cp p:9: parse error before `::' token
extract_data.cp p:11: warning: the address of
`std::ifstream ini_file_in(... )',
will always be `true'

Which include file do i need to allow the ifstream
on this gcc 3.2?

br
Anton.

Jul 22 '05 #1
7 3233
Anton Ishmurzin wrote:
ifstream ini_file_in("fi lename.dat", ios::in);


#include <fstream>

ifstream ini_file_in("fi lename.dat");

The above should work.

If you must specify the mode, my documentation says:

ifstream ini_file_in("fi lename.dat", ios_base::in);

but it's redundant.

Jul 22 '05 #2
On Tue, 25 Nov 2003 16:19:59 +0100, Anton Ishmurzin <na***@izh.co m>
wrote:
Greetings All,

I think everybodyknows the answer already. But i
am quite a newbie in c++.

I've got the following line in my code:

ifstream ini_file_in("fi lename.dat", ios::in);

But, the gcc (GCC) 3.2 spits out some stuff about
deprecated headers:
Which include file do i need to allow the ifstream
on this gcc 3.2?


You need <fstream> (no .h). But you also need use use namespace std,
the namespace containing the standard libraries. e.g.

#include <fstream>

std::ifstream ini_file_in("fi lename.dat", std::ios::in);

Tom

C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #3
Anton Ishmurzin <na***@izh.co m> wrote in message news:<3F******* *******@izh.com >...
Greetings All,

I think everybodyknows the answer already. But i
am quite a newbie in c++.
Anton...read the warning carefully...it' s really quite clear. Use
#include <fstream> to get rid of the warning.
warning: This file includes at least one
deprecated or antiquated header. Please consider
using one of the 32 headers found in section
17.4.1.2 of the C++ standard. Examples include
substituting the <X> header for the <X.h> header
for C++ includes, or <sstream> instead of the
deprecated header <strstream.h> .

Jul 22 '05 #4

"Grumble" <in*****@kma.eu .org> wrote in message
news:bp******** **@news-rocq.inria.fr.. .
Anton Ishmurzin wrote:
ifstream ini_file_in("fi lename.dat", ios::in);
#include <fstream>

ifstream ini_file_in("fi lename.dat");

The above should work.


No it shouldn't.

Make it

std::ifstream ini_file_in("fi lename.dat");

If you must specify the mode, my documentation says:

ifstream ini_file_in("fi lename.dat", ios_base::in);
std::ifstream ini_file_in("fi lename.data", std::ios_bas::i n);

but it's redundant.


Correct.

-Mike
Jul 22 '05 #5
Yes, this solves the problem with the obsolete header. But what's wrong
with this code:

ishmurzi@myhost :/home/ishmurzi/newcode> cat extract_data.cp p
#include <iostream> //
#include <fstream> //
using namespace std;

int main() {

ifstream ini_file_in("in i_file", ios::in);

if (! ini_file_in)
{
cerr << "cannot open the ini file" << endl;
exit(1);
}
else
{
cout << "ini-file opened successfully." << endl;
};

cout << "extracting data" << endl;

return 0;
}

if i compile it with icc then it's comiles even with no warnings and remarks.

but if i ask gcc to do the same, it complains about undefined references:

ishmurzi@myhost :/home/ishmurzi/newcode> gcc -Wall extract_data.cp p
/tmp/cczlKupx.o: In function `main':
/tmp/cczlKupx.o(.tex t+0x26): undefined reference to
`std::basic_ifs tream<char, std::char_trait s<char>
::basic_ifstre am[in-charge](char const*, std::_Ios_Openm ode)' /tmp/cczlKupx.o(.tex t+0x3d): undefined reference to `std::basic_ios <char,
std::char_trait s<char> >::operator!( ) const'
/tmp/cczlKupx.o(.tex t+0x4c): undefined reference to
`std::basic_ost ream<char, std::char_trait s<char> >& std::endl<char,
std::char_trait s<char> >(std::basic_os tream<char, std::char_trait s<char> >&)'
/tmp/cczlKupx.o(.tex t+0x59): undefined reference to `std::cerr'
/tmp/cczlKupx.o(.tex t+0x5e): undefined reference to
`std::basic_ost ream<char, std::char_trait s<char> >& std::operator<<
<std::char_trai ts<char> >(std::basic_os tream<char, std::char_trait s<char>&, char const*)' /tmp/cczlKupx.o(.tex t+0x67): undefined reference to
`std::basic_ost ream<char, std::char_trait s<char>::operator<<(s td::basic_ostre am<char, std::char_trait s<char> >& (*)(std::basic_ ostream<char, std::char_trait s<char> >&))'
/tmp/cczlKupx.o(.tex t+0x7c): undefined reference to
`std::basic_ost ream<char, std::char_trait s<char> >& std::endl<char,
std::char_trait s<char> >(std::basic_os tream<char, std::char_trait s<char> >&)'
/tmp/cczlKupx.o(.tex t+0x89): undefined reference to `std::cout'
/tmp/cczlKupx.o(.tex t+0x8e): undefined reference to
`std::basic_ost ream<char, std::char_trait s<char> >& std::operator<<
<std::char_trai ts<char> >(std::basic_os tream<char, std::char_trait s<char>&, char const*)'


and so on, but only concerning std:something.

What's going on? Shouldnt i use the "-l" switch? I mean something like

$ gcc -Wall -lsome_lib extract_data.cp p

?

thanks a lot in advance,
Anton.


Jul 22 '05 #6
Anton Ishmurzin wrote:
Yes, this solves the problem with the obsolete header. But what's
wrong with this code:

ishmurzi@myhost :/home/ishmurzi/newcode> cat extract_data.cp p
#include <iostream> //
#include <fstream> //
using namespace std;

int main() {

ifstream ini_file_in("in i_file", ios::in);

if (! ini_file_in)
{
cerr << "cannot open the ini file" << endl;
exit(1);
}
else
{
cout << "ini-file opened successfully." << endl;
};

cout << "extracting data" << endl;

return 0;
}

if i compile it with icc then it's comiles even with no warnings and
remarks.

but if i ask gcc to do the same, it complains about undefined
references:

ishmurzi@myhost :/home/ishmurzi/newcode> gcc -Wall extract_data.cp p
/tmp/cczlKupx.o: In function `main':
/tmp/cczlKupx.o(.tex t+0x26): undefined reference to
`std::basic_ifs tream<char, std::char_trait s<char>
>::basic_ifstre am[in-charge](char const*, std::_Ios_Openm ode)' /tmp/cczlKupx.o(.tex t+0x3d): undefined reference to
`std::basic_ios <char, std::char_trait s<char> >::operator!( ) const'
/tmp/cczlKupx.o(.tex t+0x4c): undefined reference to
`std::basic_ost ream<char, std::char_trait s<char> >& std::endl<char,
std::char_trait s<char> >(std::basic_os tream<char,
std::char_trait s<char> >&)' /tmp/cczlKupx.o(.tex t+0x59): undefined
reference to `std::cerr' /tmp/cczlKupx.o(.tex t+0x5e): undefined
reference to `std::basic_ost ream<char, std::char_trait s<char> >&
std::operator<< <std::char_trai ts<char> >(std::basic_os tream<char,
std::char_trait s<char>
>&, char const*)'

/tmp/cczlKupx.o(.tex t+0x67): undefined reference to
`std::basic_ost ream<char, std::char_trait s<char>
>::operator<<(s td::basic_ostre am<char, std::char_trait s<char> >&

(*)(std::basic_ ostream<char, std::char_trait s<char> >&))'
/tmp/cczlKupx.o(.tex t+0x7c): undefined reference to
`std::basic_ost ream<char, std::char_trait s<char> >& std::endl<char,
std::char_trait s<char> >(std::basic_os tream<char,
std::char_trait s<char> >&)' /tmp/cczlKupx.o(.tex t+0x89): undefined
reference to `std::cout' /tmp/cczlKupx.o(.tex t+0x8e): undefined
reference to `std::basic_ost ream<char, std::char_trait s<char> >&
std::operator<< <std::char_trai ts<char> >(std::basic_os tream<char,
std::char_trait s<char>
>&, char const*)'


and so on, but only concerning std:something.

What's going on?


This is getting compiler specific, but anway. You're using gcc instead
of g++ for your C++ code. When used for linking, that means that the
things needed for C++ (like e.g. the C++ standard library) are not
linked in.
Shouldnt i use the "-l" switch?


No, just use g++ for C++, and gcc for C.

Jul 22 '05 #7


Rolf Magnus wrote:
Anton Ishmurzin wrote:

Yes, this solves the problem with the obsolete header. But what's
wrong with this code:

ishmurzi@myho st:/home/ishmurzi/newcode> cat extract_data.cp p
#include <iostream> //
#include <fstream> //
using namespace std;

int main() {

ifstream ini_file_in("in i_file", ios::in);

if (! ini_file_in)
{
cerr << "cannot open the ini file" << endl;
exit(1);
}
else
{
cout << "ini-file opened successfully." << endl;
};

cout << "extracting data" << endl;

return 0;
}

if i compile it with icc then it's comiles even with no warnings and
remarks.

but if i ask gcc to do the same, it complains about undefined
references:

ishmurzi@myho st:/home/ishmurzi/newcode> gcc -Wall extract_data.cp p
/tmp/cczlKupx.o: In function `main':
/tmp/cczlKupx.o(.tex t+0x26): undefined reference to
`std::basic_i fstream<char, std::char_trait s<char>
>::basic_ifstre am[in-charge](char const*, std::_Ios_Openm ode)'

/tmp/cczlKupx.o(.tex t+0x3d): undefined reference to
`std::basic_i os<char, std::char_trait s<char> >::operator!( ) const'
/tmp/cczlKupx.o(.tex t+0x4c): undefined reference to
`std::basic_o stream<char, std::char_trait s<char> >& std::endl<char,
std::char_tra its<char> >(std::basic_os tream<char,
std::char_tra its<char> >&)' /tmp/cczlKupx.o(.tex t+0x59): undefined
reference to `std::cerr' /tmp/cczlKupx.o(.tex t+0x5e): undefined
reference to `std::basic_ost ream<char, std::char_trait s<char> >&
std::operator << <std::char_trai ts<char> >(std::basic_os tream<char,
std::char_tra its<char>
>&, char const*)'

/tmp/cczlKupx.o(.tex t+0x67): undefined reference to
`std::basic_o stream<char, std::char_trait s<char>
>::operator<<(s td::basic_ostre am<char, std::char_trait s<char> >&

(*)(std::basi c_ostream<char, std::char_trait s<char> >&))'
/tmp/cczlKupx.o(.tex t+0x7c): undefined reference to
`std::basic_o stream<char, std::char_trait s<char> >& std::endl<char,
std::char_tra its<char> >(std::basic_os tream<char,
std::char_tra its<char> >&)' /tmp/cczlKupx.o(.tex t+0x89): undefined
reference to `std::cout' /tmp/cczlKupx.o(.tex t+0x8e): undefined
reference to `std::basic_ost ream<char, std::char_trait s<char> >&
std::operator << <std::char_trai ts<char> >(std::basic_os tream<char,
std::char_tra its<char>
>&, char const*)'


and so on, but only concerning std:something.

What's going on?

This is getting compiler specific, but anway. You're using gcc instead
of g++ for your C++ code. When used for linking, that means that the
things needed for C++ (like e.g. the C++ standard library) are not
linked in.

Shouldnt i use the "-l" switch?

No, just use g++ for C++, and gcc for C.


Thanks a lot, Rolf. Now it works perfect.
Thanks everybody participated!!!

Anton.

Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2503
by: flips | last post by:
OK this is really simple but I can't think what is the best and most elegant solution. Say I am getting an int from an ifstream as follows: int val; inFile.get(reinterpret_cast<char*>(&val), sizeof(val)); How do I know if this succeeded? It only returns false if the eof is at the end of the int.
4
3730
by: hall | last post by:
Hi. I ran across a bug in one of my problems and after spending some time tracking it down i found that the problem arose in a piece of code that essentially did this: ----------- ifstream in("in.txt"); if(!in) {cout << "error\n";} in.close(); if(!in) {cout << "error\n";} in.close(); if(!in) {cout << "error\n";}
5
1897
by: Francis Bell | last post by:
I just found that my fin stream is not getting passed to my readInASpinnerbait function. Here's what I have: string readInFirstChars(ifstream &fin) { char first; string print; while (fin.good()) { fin.get(first, 4, '/');
1
6249
by: inkapyrite | last post by:
Hi all. I'm using ifstream to read from a named pipe but i've encountered an annoying problem. For some reason, the program blocks on reading an ifstream's internal buffer that's only half-filled. Only when the buffer becomes full does it resume execution. Here's my test code for reading from a pipe: //(compiled with g++ -std=c++98) //--------------------------------------------- #include <iostream>
6
5289
by: Dave | last post by:
In .Net 2003 if a line, read from a text file is larger than a size parameter, the ifstream getline(buff, sze) put the file pointer to the EOF, so next peek() returns EOF. I saw this problem also when size was 2000 but line was 1200 bytes long. There is no such problem with .Net 2002 For .Net 2003 I used : #include <string> #include <fstream>
2
2130
by: Massimo Soricetti | last post by:
Hello, I'm trying to fix this little class: <code> #include <ifstream> #include <iostream> #include <iomanip> using namespace std;
4
4740
by: manontheedge | last post by:
i'm working on a C++ program that uses operator overloads (which i'm just learning to use), and i have the ostream working fine, but i'm thinking i'm using it wrong somehow because the ofstream doesn't work. Here's some code fragments... class matrix { public: ...... friend ostream& operator << ( ostream& os, matrix& m );
2
1422
by: Gaby Glockner | last post by:
Hello folks, I'm desperate! I've written a subroutine on my Windows XP laptop and it works separately. But once I've included this subroutine into a bigger program it executes but then I get some message popping up that a problem occurs although it compiles fine. There is a ifstream line in my main program which is absolutely independent of the subroutine. Once I've removed this line
7
3225
by: Boltar | last post by:
Hi I'm using ifstream (which I hardly ever use) to read an ascii text file (containing numbers delimited by newlines) in a loop using something like: ifstream infile("filename") int value; infile >value;
0
8680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9169
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7738
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.