0

I have been making a project on C++ and I am having trouble assigning a value to a string name. I made sure to include the string library (and I did try string.h), but when I attempted to assign a value to the string name with the data type "string", it gave me the message "Error: identifier (value I assigned the string) is undefined". This is kind of what the code looked like:

string a = start;

The word "start" was underlined in red. It was weird because when I did the same thing using an integer, it worked just fine:

int a = 3;

Can somebody help? Thanks

user2602989
  • 1
  • 1
  • 2

2 Answers2

2

You need to put your value into quotes:

string a = "Hello World!";

But, you also need to include the right headers:

#include <string> //string.h is for c-strings
using namespace std; //so you don't have to do std::xxxxxx

Hope this helps.

phyrrus9
  • 1,441
  • 11
  • 26
1

See this duplicate question. You should first include the header <string> (not <string.h>), and then write your statement as std::string a = start. Here, std::string indicates that string is located in the namespace std.

Community
  • 1
  • 1