Fundamentals of C + + programming 113-strings based on string

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.