What is <string> actually for? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is <string> actually for?

I have no Idea what does Text says on my lessons and I have no Idea what is it used for? Maybe someone can give me an Understandable explanation or Demonstrate the Usage of <string> ? Thanks.

22nd Oct 2019, 2:39 PM
xXJust_JohoXx
xXJust_JohoXx - avatar
6 Answers
+ 9
We know that int can be used to store integers like 39, 42, 1, etc. In the same fashion, char is used to store characters like 'a', 'b', '£', etc. int n = 39; char c = 'a'; Strings are a collection of characters in a sequence. For example, "hello", "this is a sentence", "welcome", etc. Similar to how you would store integers in integer variables and characters in character variables, you can store strings, in string variables. #include <iostream> #include <string> int main() { std::string str = "Hello!"; std::cout << str; }
22nd Oct 2019, 2:49 PM
Hatsy Rei
Hatsy Rei - avatar
+ 7
Seb TheS From what I've read, the standard does not dictate that <iostream> should include <string>, it's mostly just the compiler (or IDEs) making things easier for us. Consider: https://stackoverflow.com/questions/43565043/visual-studio-2017-c-issue-with-string
22nd Oct 2019, 2:58 PM
Hatsy Rei
Hatsy Rei - avatar
+ 1
Isn't it self describing? It brings the string datatype to the program.
22nd Oct 2019, 2:45 PM
Seb TheS
Seb TheS - avatar
+ 1
strings are the words or alphabetical words not number or a integers which are used for giving a name or a value in python strings are like: hello="abcd" print(hello)
23rd Oct 2019, 11:57 AM
Prashant Yadav
Prashant Yadav - avatar
0
string library is already includes with iostream, so you do not need to separately include string library, if you already included iostream library.
22nd Oct 2019, 2:54 PM
Seb TheS
Seb TheS - avatar
0
Hatsy Rei How so is that Code (The one in the link) in my language? 😂
22nd Oct 2019, 5:21 PM
xXJust_JohoXx
xXJust_JohoXx - avatar