?
Solved

New to C++.  Need to know how to use a string.

Posted on 2003-03-18
3
Medium Priority
?
201 Views
Last Modified: 2010-04-01
How do i use a string?

I did #include <string.h>

but when i do

string x = "hello world";
cout<<x;

it's an error.. said "string" is an undeclared identifier..

I'm just really new to programming and don't even know how to use a string.

I'm trying to get the user to enter a number of words and then use if-then form to create a game for my final project.

thx
0
Comment
Question by:SuperSid
[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
  • 2
3 Comments
 

Author Comment

by:SuperSid
ID: 8161297
might i add that this is my code.

#include <iostream.h>
#include <string.h>




int main (void)
{
     
     string x = "hello world";
     cout<<x<<"\n";



}

error:  'string' : unidentified modifier.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 8161439
try using:

#include <string>

instead of

#include <string.h>

you also might want to check out this link:
http://www.amberman.org/evolve/Software/strings/
0
 
LVL 18

Accepted Solution

by:
bobbit31 earned 100 total points
ID: 8161464
i don't know which compiler you are using, but if it's MSVC 6.0 it should look like this:

#include <string>
using namespace std;

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

771 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