What is string in C++

I am a beginner in C++, I wanna know what is the concept of string in c++. Is it a class, object, function data type, what is it??
We can declare string bot as string st="hello"; and string str("hello");
Why??
Yes, std::string is a class and data type. In your examples st and str are objects.
std::string has an assignment operator. Your first example assigns the C-string "hello" to the object st. In this case, string's default constructor is called, then the assignment is made. *

Your second example calls string's constructor that accepts a C-string as an argument.

Why two ways to do this? default construction and assignment and construction with an explicit argument might have different semantics. In the case of std::string, there is no difference, but there could be with a user defined class. In any case, it's handy to be able to both construct a string with a C-string argument and assign a C-string to a std::string object, so std::string provides both.

* I'm not sure on this point. I think the newer standards may recognize this as construction via argument.

Topic archived. No new replies allowed.