[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

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

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
SuperSid
Asked:
SuperSid
  • 2
1 Solution
 
SuperSidAuthor Commented:
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
 
bobbit31Commented:
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
 
bobbit31Commented:
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

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now