Yahoo Clever wird am 4. Mai 2021 (Eastern Time, Zeitzone US-Ostküste) eingestellt. Ab dem 20. April 2021 (Eastern Time) ist die Website von Yahoo Clever nur noch im reinen Lesemodus verfügbar. Andere Yahoo Produkte oder Dienste oder Ihr Yahoo Account sind von diesen Änderungen nicht betroffen. Auf dieser Hilfeseite finden Sie weitere Informationen zur Einstellung von Yahoo Clever und dazu, wie Sie Ihre Daten herunterladen.

Hey Guys, what is the different between a Char and a String in C++(See Details)?

What is the Different between

char Stringvar[50];

and using the Headerfile String

string Stringvar;

I hope you've understood what I mean. I don't know how to explain differently.

3 Antworten

Relevanz
  • Cubbi
    Lv 7
    vor 1 Jahrzehnt
    Beste Antwort

    char Stringvar[50]; creates an array of 50 characters. It can be used to store and manipulate 50 chars, or, often, to store and manipulate a "C string" of no more than 49 characters. C strings (properly called "null-terminated byte strings", NTBS), have fixed size and cannot contain nulls (zero bytes, char value '\0'), since null is used to signal the end of the string.

    string Stringvar; creates an object of type string, which can hold a sequence of characters of any length, which can also contain multiple NUL bytes, and have a large number of C++ functions and algorithms that can be used to work with the contents of that string.

  • vor 1 Jahrzehnt

    A char is a primitive data type that holds a single char.

    A string is an object that represents an array of chars.

    The string object can be concatenated easily and has built in methods for modifying a string.

    If using an array of chars you will need to create your own methods for modifying the "string". however you have more control over memory management.

  • Anonym
    vor 1 Jahrzehnt

    Character constants are one or more members of the "source character set," the character set in which a program is written, surrounded by single quotation marks ('). They are used to represent characters in the "execution character set," the character set on the machine where the program executes.

    char ch = 'x'; // Specify normal character constant.

    a string is, essentially, a sequence of characters.

    string is a character sequence terminated with a null character ('\0', called NUL in ASCII).

    char Stringvar[50];

    this is defined to just 50 characters.

    string Stringvar; is open, you can store more characters..... :) i think :)

Haben Sie noch Fragen? Jetzt beantworten lassen.