[C + +] string processing

Source: Internet
Author: User

String read-in by line
getline(cin, s1);
string deletes the specified character

Move the element with the value Val to the end, and return the Newend iterator through remove in algorithm
Use String.erase to remove elements from the newend and end ranges

s1.erase(remove(s1.begin(), s1.end(), s2[i]), s1.end());
The difference between the Find function

Find is provided in both string and algorithm.

Std::find function template

Emplate <class Inputiterator, class t>
Inputiterator Find (inputiterator First, Inputiterator last, const t& val);

Input parameters

Find iterators for scopes, and find values

return value

The first iterator that matches the element that has no matching result returns the last iterator

Std::string::find overloading

String (1)
size_t Find (const string& str, size_t pos = 0) const noexcept;
C-string (2)
size_t Find (const char* s, size_t pos = 0) const;
Buffer (3)
size_t Find (const char* s, size_t pos, size_type N) const;
Character (4)
size_t Find (char c, size_t pos = 0) const noexcept;

Input parameters

STR/S/C: The string/character to look for
POS: Looking for the starting position
N: The length of the match

return value

Returns the position of the first matching element found (size_t)
Return String::npos if not found

Output specified precision

printf ("%.2f", num)

[C + +] string processing

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.