Is there a string type in C language?

Source: Internet
Author: User

I. Source of the problem

Today on the VS2010 platform, try using scanf ()

string Word;

scanf ("%s", &word);

Then the error is found and the output takes

printf ("%s\t", word);

Found also not, then converted to CIN and cout OK, so suspect is not%s out of the question, sure enough.

Because a string in C is stored in a char array, it is a combination of basic types, but string is a encapsulated class in C + +.

So the output can be used

printf ("%s\t", Word.c_str ());

But the sense of input is not saved Ah!

2. Online answer (from Baidu know)

It is not always clear to this question: just know that C language has <string.h this header file, so it is assumed that C language has string this
Type, you can declare a string of variable string astring by this form;
Later when the program found that the compilation, but also check the data to know that the original C language there is no string this type, so the string is stored through a char array,
The function prototype declared in <string.h's header file is all about the various operations of the char array. The string class was not present until C + + (note the class,
Not a type). This is the more satisfactory answer I found on the Internet:
"Is there a string type variable in the C language?"
The string here has two semantics.
(1) If string is a generic word, "C language has a character type variable", answer, yes. The character type is declared with Char.
Char str[]= "This is a string";
(2) If string is a special term, "C language has a string type variable", a, No. A string is a class, is a classes, not a type.

Is there a string type in C language?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.