| |
A short string demonstration |
|
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
string stringObject1("stringObject1");
string stringObject2("stringObject2");
string stringObject3("stringObject3");
string stringObject4;
stringObject4 = stringObject1;
cout << stringObject1 << "\n" << stringObject3 << "\n";
stringObject4 = stringObject1 + stringObject2;
cout << stringObject4 << "\n";
stringObject4 = stringObject1 + " to " + stringObject3;
cout << stringObject4 << "\n";
if(stringObject3 > stringObject1)
cout << "stringObject3 > stringObject1\n";
if(stringObject3 == stringObject1+stringObject2)
cout << "stringObject3 == stringObject1+stringObject2\n";
stringObject1 = "This is a null-terminated string.\n";
cout << stringObject1;
string str5(stringObject1);
cout << str5;
cout << "Enter a string: ";
cin >> str5;
cout << str5;
return 0;
}
|
|
|
Related examples in the same category |
1. | String type class | | | 2. | A filter to remove white-space characters at the ends of lines. | | | 3. | A string demonstration: assignment, concatenate, compare | | | 4. | Demonstrate insert(), erase(), and replace(). | | | 5. | Use string: find, string::npos | | | 6. | Strings: size, iterator, count, begin and end | | | 7. | string: find( ) and rfind( ) | | | 8. | Print a name in two different formats | | | 9. | Several string operations: substr | | | 10. | String Char Indexing | | | 11. | String Find and replace | | | 12. | String Size | | | 13. | String SizeOf | | | 14. | String insert(), erase(), and replace() | | | 15. | string variable instead of a character array | | | 16. | Inputting Multiple Words into a String | | | 17. | Adding Strings | | | 18. | Read string from console | | | 19. | Insert, search, and replace in strings. | | | 20. | Accessing Characters In Strings | | |
|