[DTOJ] 2701: Greetings, dtoj2701 greetings

Source: Internet
Author: User

[DTOJ] 2701: Greetings, dtoj2701 greetings

DTOJ 2701: greeting solution report

  • 2017.11.08 First Edition--CoolOriginal, referenceYzl_rexCSDN blog

 

Question information:Description

Greetings to humans!

Input

Enter a row and a name, such as human (string type, defined as string)

Output

Output a line, add "Hello" before the input name, and finally add! No.

Sample Input
kitty
Sample output
Hello kitty!
Ideas:

Define a string to store the name. Output "Hello" and then output the string. Note "! "(Exclamation point) also needs to be output

Note:

English halfwidth characters

My code (C ++ ):
 1 //DTOJ 2701  2 #include <iostream> 3 #include <string> 4 using namespace std; 5  6 int main() 7 { 8     string name; 9     cin>>name;10     cout<<"Hello "<<name<<"!";11     return 0;12 }
Analysis:

Row 8: string name; precompiled commands must be added to declare the string stirng variable "# include <string>". string is part of the C ++ standard library, and std must be added to the namespace::

Expansion:

The string class in C ++ must contain"# Include <string>",Note that this is not <string. h>, *. H file is the header file in C language, which is <cstring> in C ++ and requires the std namespace.

The content of the CSDN blog reposted from yzl_rex is for learning and communication purposes only:

Most functions of the string class:
Get the Iterator pointing to the beginning of the string
End obtains the Iterator pointing to the end of the string.
Rbegin obtains the Iterator pointing to the beginning of the reverse string.
Rend to get the Iterator pointing to the end of the reverse string
Returns the size of the string.
The length and size functions are the same.
Max_size the maximum possible size of a string
Possible size of the string without allocating memory again
Empty determines whether it is null
Operator [] obtains the nth element, which is equivalent to an array.
C_str: returns the C-style const char * string.
Data obtains the string content address
Operator = value assignment operator
Reserve reserved space
Swap Functions
Insert characters
Append characters
Push_back append characters
Operator ++ = operator
Erase
Clear all content in the character container
Resize re-allocates Space
Assign is the same as the value assignment operator.
Replace substitution
Copy string to Space
Find
Rfind Reverse Lookup
Find_first_of finds any character in the substring and returns the first position.
Find_first_not_of searches for any character that does not contain a substring and returns the first position.
Find_last_of finds any character in the substring and returns the last position.
Find_last_not_of searches for any character that does not contain a substring and returns the last position.
Obtain the string from substr.
Compare comparison string
Operator + String Link
Operator = judge whether it is equal
Operator! = Judge whether it is not equal
Operator <judge whether it is less
Operator> Read strings from the input stream
Operator <string writing to the output stream
Getline reads a row from the input stream

 


This work is licensed using the knowledge sharing signature-non-commercial use-share the 4.0 international license agreement in the same way.

-- Qoreng's Funny match w

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.