1 //13-string based on String.cpp: Defines the entry point of the console application. 2 //3 4#include"stdafx.h"5#include <iostream>6#include <climits>7#include <string>//introducing the String class library8 using namespacestd;9 Ten One intMain () A { - stringstr1; - stringSTR2 ="wwww.uimodel.com"; thecout << str1 <<Endl; -cout << str2 <<Endl; -STR1 = str2;//compared to the C language, C + + introduces a String class library and can assign a value to a string variable. -cout << str1 <<Endl; + -cout <<"Please enter a passage:"; + //cin >> str1;//If you use CIN to receive user input, no whitespace is allowed in the input information. AGetline (CIN,STR1);//You can use the Getline () method to receive information for an entire row. atcout << str1 <<Endl; - -cout << str2[5] << Endl;//Accessing a String class in C + + essentially accesses a character array, so you can access the values in the array by using a character array index (subscript). - - //string s= "Uimodel" + ". com";//This syntax is wrong because "Uimodel" and ". com" are not represented by the string type. -STR1 ="Uimodel";//so they are all defined as string types and then added together. inSTR2 =". com"; - strings = str1 +str2; tos + =str1; +cout << S <<Endl; - the //get the number of characters *cout << s.size () <<Endl; $ Panax Notoginseng intT; -CIN >>T; the return 0; +}
Fundamentals of C + + programming 113-strings based on string