C ++ string processing

Source: Internet
Author: User
Tags string find
# Include <iostream> # include <string> # include <stdio. h> using namespace std; int main () {string s; char ch; ch = cin. get (); // cin. get () receives one character at a time; cout <ch <endl; ch = getchar (); // getchar () receives one character at a time; cout <ch <endl; getline (cin, s); // getline () receives a string and can receive spaces. cout <s <endl; char m [20]; cin. getline (m, 5); // cin. getline () receives a fixed-length string and can receive spaces. cout <m <endl; gets (m); // gets () receives a string and can receive spaces; cout <m <endl; char n [3] [10]; for (int I = 0; I <3; I ++) gets (n [I]); // gets () can also be used in multi-dimensional arrays; for (int j = 0; j <3; j ++) cout <n [j] <endl; return 0 ;}
Enter the following 1000 numbers:
731671765313306249192251196744265747423553491949349698352031277450632623957831801698480186947885184385861560789112949495459501737958331952853208805511125406987471585238630507156932909632952274430435576689664895044524452316173185640309871112172238311362229893423380308135336276614282806444486645238749303589072962904915604407723907138105158593079608667017242712188399879790879227492190169972088809377665727333001053367881220235421809751254540594752243525849077116705560136048395864467063244157221553975369781797784617406495514929086256932197846862248283972241375657056057490261407972968652414535100474821663704844031998900088952434506585412275886668811642717147992444292
8230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694
165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450
#include<iostream>#include<cstdio>using namespace std;string s;int main(){    freopen("1.txt","r",stdin);    for(int i=0; i<1000; i++)        if(s[i]=='\n')        {            getchar();        }        else            cin>>s[i];    for(int i=0; i<20; i++)        cout<<s[i]<<endl;        cout<<s[999]<<endl;    return 0;}
/* C ++ Strings (string) Constructors, used to initialize the Operators operator for string comparison and assignment. append () adds the text assign () to the end of the string () assign a new value to the string at () according to the given index value returned character begin () returns an iterator, pointing to the first character c_str () returns the string in the form of a C character array capacity () returns the character capacity before the space is reassigned. compare () compares the two strings copy () to copy the content into a character array. The data () returns the content in the form of an empty () character array () if the string is null, return true end () to return an iterator pointing to the end of the string. (Next location of the last character) erase () delete character find () in the string find character find_first_of () find the first character that is equal to a value in value find_first_not_of () find the character find_last_of () that is not equal to all values in the first and value to find the character find_last_not_of () that is equal to a value in the last and value () find the character get_allocator () that is not equal to all values in the last value. Return to the configurator insert (). insert the length (). Return the length of the string. max_size () returns a reverse iterator pointing to the last character rend (), pointing to the previous position of the first element replace () replace character reserve () retain a certain capacity to hold the string (set the capacity value) resize () reset the string size rfind () Find the last character equal to the value (reverse search) size () returns the number of characters in the string. substr () returns a substring. swap () exchanges the content of two strings */

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.