Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Can't seem to implement the string header properly

Posted on 2003-02-27
9
Medium Priority
?
261 Views
Last Modified: 2010-04-17
Hi,

I'm using C++ on Red Had Linux 8.0. I'm using g++ to compile my programs. I've properly inserted the <iostream> header, but it seems that the others I try do not work correctly.

For instance, I've been trying to use <string> and <fstream> but both give me errors. When I use #include <string> and then implement the string code in my program, such as string x = "test"; I receive the following error:

block_good.cc: In function `int main()':
block_good.cc:58: `string' undeclared (first use this function)
block_good.cc:58: (Each undeclared identifier is reported only once for each
   function it appears in.)
block_good.cc:58: parse error before `=' token

Any help would be great.

Thanks!
0
Comment
Question by:bgriscom
  • 4
  • 3
  • 2
9 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 8034766
try
#include <string.h>

mlmcc
0
 

Author Comment

by:bgriscom
ID: 8035970
I tried changing it to string.h. No dice.
0
 

Author Comment

by:bgriscom
ID: 8036149
I tried changing it to string.h. No dice.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Accepted Solution

by:
JZ4096 earned 200 total points
ID: 8036729
Perhaps the standard namespace has not been included. Try inserting

#include <string>
using std::string;

or

#include <string>
using namespace std;

at the beginning of the file.

The former brings std::string into the global namespace, whereas the latter brings all elements of the standard namespace.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 8038672
Is the file string.h and filestream.h in the correct directory on the machine?

mlmcc
0
 

Author Comment

by:bgriscom
ID: 8038694

Using the #include <string> and "using std::string" fixes the problem!

I don't understand why I didn't have to do this in my computer science courses. Do I need to modify a header file to include this automatically?

Thanks for the assistance.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 8039015
Did you happen to use MS VC++?  If so it can be setup to not requie the std:

gnu I believe requires it.  There is a way around it but I forget what it is.

SOmething like
Using <String.h>

mlmcc
0
 

Author Comment

by:bgriscom
ID: 8041710
Thanks to everyone for the help. If you have any ideas as to why I never had to include this before or if it was built into my header file, please let me know.

Thanks.

Thanks to mlmcc and JZ4096 for the assistance.
0
 

Expert Comment

by:JZ4096
ID: 8044333
Including <string.h> does not include C++'s new STL string class, but only C's string manipulation functions (strcat, strlen, strcmp, etc).

Including <string> includes the STL string, but it is in namespace std by default.  To bring it into the global namespace, using namespace std; or using std::string; is necessary.

~JZ4096
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
No other job is as rewarding and demanding as building an iPhone app is. It is not really in the hands of the developer for the success of an iPhone app. Many factors operate jointly for every iOS application's success in the market.
Introduction to Processes
Loops Section Overview

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question