?
Solved

Can't seem to implement the string header properly

Posted on 2003-02-27
9
Medium Priority
?
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

777 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