+ 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.
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;
}
+ 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
+ 1
Isn't it self describing?
It brings the string datatype to the program.
+ 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)
0
string library is already includes with iostream, so you do not need to separately include string library, if you already included iostream library.
0
Hatsy Rei How so is that Code (The one in the link) in my language? đ