Basic string operations in C ++

Source: Internet
Author: User

# Include <iostream> <br/> # include <string> <br/> # include <cstdlib> <br/> using namespace STD; <br/> int main () <br/>{< br/> string STR = "the Chinese People's Republic of China Beijing five-star red flag volunteer army march"; <br/> string str_temp = ""; <br/> str_temp.assign (STR); <br/> string result [4] = {"","","",""}; <br/> int position = 0; <br/> for (INT I = 0; I <3; I ++) <br/>{< br/> position = str_temp.find (""); <br/> result [I] = str_temp.substr (0, position); <br/> str_temp = str_temp.su BSTR (Position + 1, str_temp.length ()-position); <br/>}< br/> result [3] = str_temp; <br/> cout <"country: "<result [0] <Endl; <br/> cout <" Capital: "<result [1] <Endl; <br/> cout <"flag:" <result [2] <Endl; <br/> cout <"national anthem: "<result [3] <Endl; <br/> str_temp.swap (result [0]); <br/> for (Int J = 1; j <4; j ++) <br/>{< br/> str_temp + = ""; <br/> str_temp.append (result [J]); <br/>}< br/> int equal = Str. compare (str_temp); <br/> If (equal = 0) <br />{< Br/> cout <"the string is the same and the match is successful! "<Endl; <br/>}< br/> else <br/> cout <" the string is different and the match is unsuccessful! "<Endl; </P> <p> // cout <str_temp <Endl; <br/> return exit_success; <br/>}

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.