answersLogoWhite

0

What is string in c plus plus?

Updated: 8/11/2023
User Avatar

Wiki User

14y ago

Best Answer

A String is a variable that represents a list, or array, of characters. They are normally assigned using double quotes (""). When using strings you must import string header file

#include

and then an example of a string

string mystring = "This is a string";

This give the variable 'mystring' a value of "This is a string".

A string can also be referred to as an array of characters

char string [10];

Would make the variable string to an array of characters with length ten.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

String are the same in most languages: they are simply an array of type char. In C++, as in C before it, all strings are treated as being null-terminated strings. In C++, however, the array is implemented as an object, of type std::string, thus the string has member methods that are familiar to most string objects, including append, at, insert, replace, substr and so on.

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

An ANSI string is a string where each character is encoded according to one of the Windows extended ASCII character sets, usually code page 1252, which Microsoft errantly refers to as the ANSI code page. The problem is that ANSI never issued any such standard, so the term is essentially meaningless. It could mean code page 1252, or it could mean any one of the Windows extended ASCII character sets. Or it could mean all of them together!

To clarify, ANSI (American National Standards Institute) is responsible for overseeing standards development and accrediting standards developers. It is a founder member of ISO (International Organisation for Standardisation) and is the official US representative of the IEC (International Electrotechnical Commission).

ASCII (American Standards Committee for Information Interchange) is an encoding scheme that utilises a 7-bit encoding, which encapsulates the first 128 character codes, including alphanumeric symbols (uppercase and lowercase), common arithmetic symbols, whitespace, control codes and other common symbols. These symbols are common to all code pages, and is therefore known as the ASCII character set. An extended ASCII character set uses the 8th bit to denote another set of 128 symbols.

Code page 1252 began life in 1974 as ECMA-43. It was an 8-bit extended ASCII character set proposed by the European Computer Manufacturers Association and the set was finally adopted by ISO in 1985. Microsoft implemented it in Windows 3.0 in 1990, replacing PU1 and PU2 (private-use codes) with curly apostrophes. But, in order to compete with the Macintosh desktop publishing market, Microsoft then replaced many of the ISO-defined control characters and implemented this completely non-standard extended ASCII character set in Windows 3.1. This particular character set was listed as IBM code page 1252, but was never standardised by ANSI. Nevertheless, Microsoft named it the ANSI code page. But for some unfathomable reason, all the other Windows extended ASCII character sets also became known as ANSI code pages. Hence the term has no practical meaning.

When confronted with a so-called ANSI string object, there is no way to determine which code page should be applied to it. Code page 1252 is a fairly reasonable assumption, but if the string were encoded using a central European code page, a Vietnamese code page, Turkish, Greek, or any other Windows extended ASCII code page, the string will not be displayed properly. Thus ANSI strings are best avoided altogether.

ASCII and UNICODE are the worldwide standard for encoding strings, with UTF-8 being the most common as it doesn't suffer the problem of endianness (as with UTF-2, UTF-16 and UTF-32), and is backwardly-compatible with the 7-bit ASCII character set. The only drawback is that in order to determine the length of a string, you must process the control sequences (character codes greater than 127) to reduce the variable-length code points (which can extend to up to 6 bytes) to a single character.

UNICODE can essentially be split into two varieties: fixed-width and variable-width code points. The variable-width UNICODE encodings are also known as MBCS (multi-byte character sets), and include UTF-8 and UTF-16. UTF-2 and UTF-32 are fixed-width (2 bytes and 4 bytes, respectively).

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is string in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How can you get a specific string from large string using c plus plus strings?

std::string::substr();


What is the difference between a C plus plus string and a C-style string?

A std::string is an object that encapsulates an array of type char whereas a C-style string is a primitive array with no members. A std::string is guaranteed to be null-terminated but a C-style string is not.


C plus plus library functions for string operations?

You can use "string" class in C++ for string operations or you may use c style string functions as well. #include <string> String class in C++ provides all basic function to operate on strings. you may details descriptin at http://www.cplusplus.com/reference/string/string/


What is the program to create a string class which stores a string value in c plus plus?

C++ already provides a string class in the C++ standard template library. #include<iostream> #include<string> int main() { using namespace std; string s {"Hello world!"}; cout << s << endl; }


C plus plus program to count digit in a string?

Use the following function to count the number of digits in a string. size_t count_digits (const std::string& str) { size_t count = 0; for (std::string::const_iterator it=str.begin(); it!=str.end(); ++it) { const char& c = *it; if (c>='0' && c<='9'); ++count; } return count; }

Related questions

How can you get a specific string from large string using c plus plus strings?

std::string::substr();


What is the difference between a C plus plus string and a C-style string?

A std::string is an object that encapsulates an array of type char whereas a C-style string is a primitive array with no members. A std::string is guaranteed to be null-terminated but a C-style string is not.


Is there a datatype string in c plus plus?

Yes.


C plus plus library functions for string operations?

You can use "string" class in C++ for string operations or you may use c style string functions as well. #include <string> String class in C++ provides all basic function to operate on strings. you may details descriptin at http://www.cplusplus.com/reference/string/string/


What is the role of plus operator between two string constant?

The plus operator between string constants allows string concatination: string a = "Hello, "; string b = "World!"; string c = a + b; The output of c would be: "Hello, World!".


What is the program to create a string class which stores a string value in c plus plus?

C++ already provides a string class in the C++ standard template library. #include<iostream> #include<string> int main() { using namespace std; string s {"Hello world!"}; cout << s << endl; }


How print the string with double cot in c plus plus language?

console.wrikerle("""");


Why can't the c plus plus compiler find the string object?

The most likely reason that the C++ compiler can't find the string object is just that you've forgotten to include the string header file.Code Example:#include // so you can use C++ strings using namespace std; // so you can write 'string' instead of 'std::string' string sMyString; // declare a string


C program plus copy of string to another?

strcpy


Do I need to write a program to find a substring in a given string in c plus plus?

No.


C plus plus program to count digit in a string?

Use the following function to count the number of digits in a string. size_t count_digits (const std::string& str) { size_t count = 0; for (std::string::const_iterator it=str.begin(); it!=str.end(); ++it) { const char& c = *it; if (c>='0' && c<='9'); ++count; } return count; }


C plus plus program to perform string manipulation?

You do not need to program string manipulation as it is already part of the standard library. See std::string and std::wstring.