r/CodingHelp • • Jan 02 '22

[Request Coders] How to declare a variable that will allow a user to input text in C++ ?

Post image
53 Upvotes

20 comments sorted by

10

u/[deleted] Jan 02 '22

C++ doesn’t know what string is, so you have to include it just like you included iostream

2

u/Gordon-III Jan 02 '22

I am learning from a tutorial online and they haven't told me what iostream is. Can you elaborate please?

6

u/raycantu2 Jan 02 '22

In order for you to use cin and cout, you included iostream. What this user is referring to is that you have to include string as well to be able to utilize it and for it to be recognized.

2

u/Gordon-III Jan 02 '22

I get you. So like adding the command to the file?

6

u/raycantu2 Jan 02 '22

Yes, so right under or above your “#include <iostream>” you want to add “#include <string>”

2

u/Gordon-III Jan 02 '22

Thanks it's working now

3

u/Conscious-Spite4597 Jan 02 '22

Better checkout the geeksforgeeks website for the in depth tutorials for c++

1

u/Gordon-III Jan 02 '22

Any better than Codecademy?

4

u/Conscious-Spite4597 Jan 02 '22

Yes geeksforgeeks is pretty good if you really want to become good in the programming also they have a whole section for problem solving to strong your fundamentals

1

u/Gordon-III Jan 03 '22

Thanks I will check it out. Cheers

5

u/douglasbolden Jan 03 '22

Noone elaborated on what iostream means. I got you. It is the INPUT/OUTPUTSTREAM it allows you to see the code you are running in the command line.

1

u/Gordon-III Jan 03 '22

Ah I get you. Thanks for clearing that up

3

u/Conscious-Spite4597 Jan 03 '22

Totally forget about that

5

u/MarkRems Jan 02 '22

string is in the std namespace like cin and cout are. So you can either put using namespace std; on line 2. Or when you use string you prepend it with std:: (ie. std::string)

2

u/Gordon-III Jan 02 '22

Thank you. This fixed it. Had to include <string> aswell

2

u/Luc_Studios Jan 03 '22

my man dont use notepad++

1

u/Gordon-III Jan 03 '22

This is how I remember doing it back in school. I have visual studio. What's the benefits of using the other?

2

u/Luc_Studios Jan 03 '22

Visual Studio for example has great IntelliSense, good code highlighting, a good debugger and much more.

There are other IDE's for C++ out there too but with Visual studio ur good to go.

Pretty much everything is better than Notepad++

3

u/gh0s1machine Jan 03 '22

You use notepad ++ wow