Declaring a string in C++

Hi, in the “Dog Years” codecademy assignment I tried to ask a user input for their dog’s name, just to challenge myself. So in the main function, I declared a string variable as such:

string dog_name;

However I kept getting an error when I compiled and saved. The computer didn’t recognize the variable. I tried using the char variable type and that worked. I’ll post a link of my assignment below, if anyone can help that would be awesome!

Link

Hey there and welcome to the community :slight_smile:
Could you post your full code?

You can use the string type in C++ a couple different ways.

You can use as part of the std namespace:

#include <iostream>

int main(void) {
  std::string words = "Hello World";
//  \
//   std namespace
  return 0;
}

Or if you want to use it without the namespace (as your above example shows) than you need to include the line using namespace std:

#include <iostream>

using namespace std;
int main(void) {
  string words = "Hello World";
//   \
//    Now there is no need to include the namespace
  return 0;
}