answersLogoWhite

0

Examples:

#include <iostream>

#include <string>

using namespace std;

int main()

{

string st = "hello world!";

cout << st << endl;

char c[] = "hello world!";

cout << c << endl;

char a[13] = {'h','e','l','l','o',' ','w','o','r','l','d','!' };

cout << a << endl;

char * s;

s = ( char * ) malloc( 13 );

memset( s, 0, 13 );

s[0] = 'h';

s[1] = 'e';

s[2] = 'l';

s[3] = 'l';

s[4] = 'o';

s[5] = ' ';

s[6] = 'w';

s[7] = 'o';

s[8] = 'r';

s[9] = 'l';

s[10] = 'd';

s[11] = '!';

cout << s << endl;

free( s );

return( 0 );

}

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

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


What is the code in c plus plus to declare and define a structure keeping records of 10 students?

struct student { std::string id; std::string first_name; std::string last_name; // ... }; student students[10];


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!".


How do you declare a pointer to a character string in c?

char *ptr;


Can you declare a method within a method in c or c plus plus?

C: there are no methods in C. C++: no.


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 &lt;string&gt; String class in C++ provides all basic function to operate on strings. you may details descriptin at http://www.cplusplus.com/reference/string/string/


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

console.wrikerle("""");


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&lt;iostream&gt; #include&lt;string&gt; int main() { using namespace std; string s {"Hello world!"}; cout &lt;&lt; s &lt;&lt; endl; }


How do you declare a string array and add elements to it in C plus plus?

You cannot add elements to a fixed array in C or C++. If, however, the array is declared as a pointer to an array, you can add elements by allocating a new array, copying/adding elements as needed, reassigning the new array to the pointer, and deallocating the original array.