www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/02/07/11:16:56

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
From: pavenis AT lanet DOT lv
To: Hayden Muhl <hmuhl AT iastate DOT edu>, djgpp AT delorie DOT com
Date: Thu, 7 Feb 2002 18:15:28 +0200
MIME-Version: 1.0
Subject: Re: Using strings in DJGPP
Message-ID: <3C62C440.13600.1DE0D1F@localhost>
In-reply-to: <200202071335.HAA24357@mailhub-1.iastate.edu>
X-mailer: Pegasus Mail for Windows (v4.01)
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On 7 Feb 2002 at 7:35, Hayden Muhl wrote:

> I don't get this.  I have been trying to get DJGPP to work, but it does not 
> like strings at all.  Here is my program.
> 
> #include <string.h>
> #include <fstream.h>
> #include <iostream.h>
> 
> int main()
> {
> string a = "Yo";
> cout << a;
> return 0;
> }
> 
> and here is the error I get.
> 
> search.cpp: In function `int main()':
> search.cpp:7: `string' undeclared (first use this function)
> search.cpp:7: (Each undeclared identifier is reported only once for each
>    function it appears in.)
> search.cpp:7: parse error before `=' token
> search.cpp:8: `a' undeclared (first use this function)

Of course it's so with gcc-3.X as string now is in std namespace.
So use std::string instead of string or put 'using namespace std;' earlier 

> I have tried changing the line #include <string.h> to a ton of different stuff, 
> but nothing works.  Here's a list of SOME of the the stuff I have tried.
> 
> #include <string>
> #include <String.h>
> #include <_String.h>

_String.h is from libg++. It DOES NOT work with gcc-3.X and perhaps
never will. libg++ is dead and it's use is discouraged

> #include <cstring.h>
> #include <basic_string.h>
> 
> I don't get it.  Did I get a bad version of the compiler?  Other header files 
> work fine.  iostream and fstream work beautifully, but not string.  I just 
> don't get it.
> 
Maybe  iostream  and fstream classes work if You include
iostream.h and fstream.h which is also obsolete and will soon be deprecated
(Expect to get warning about that when gcc-3.1 will be released).
One should use 
	#include <iostream>
	#include <fstream>
etc. instead. Note that You'll get all classes in std namespace

Andris






- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019