Sign in to follow this  
void[]

String Library Question

Recommended Posts

Hi guys.

I have been learning the basics of c++ from Kevin's tutorials, and I have a big question.

What does #include <string> really do? 

String is a variable, so why isn't it inherent of c++?  Why do you have to include the string libraries? 

Thanks. 

Share this post


Link to post
Share on other sites

 

Hi, I just have a couple of questions.

 

For multiple if - statements, why do you put an if statement inside of an else statement?  Wouldn't it be easier to just use else if?

 

What does #include <string>  do?  I don't understand why you have to include libraries just to use a variable type. 

 

Thanks a lot.

 

String is not included as a primitive object in C++. There is no concept of a string out of the box with C++, however, there is a concept of an array of characters. To make using strings easier the string class was created. When you type the line #include <string> you are adding that class (the string class) to your project. Under the hood the string class uses an array of characters. 

Remember, that string is not a variable (neither is int or char). These are types, or in the case of string, and object (aka class).

String is not included by default in C++ because C++ is a very bare bones language. It gives you the bear minimum and it is the programmers responsibility to add on to that. That is one of the reasons C++ is so powerful; because it does not have all that extra "stuff" (like string) it is very lightweight out of the box. 

 

If statement question: Yes in most cases using else if is easier. Did it for the sake of showing different ways to do things.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this