std::string::at can be used to extract characters by characters from a given string.
It supports two different syntaxes both having similar parameters:
char& string::at (size_type idx)
const char& string::at (size_type idx) const idx : index number Both forms return the character that has the index idx (the first character has index 0). For all strings, an index greater than or equal to length() as value is invalid. If the caller ensures that the index is valid, she can use operator , which is faster. Return value : Returns character at the specified position in the string. Exception : Passing an invalid index (less than 0 or greater than or equal to size()) throws an out_of_range exception.
std::string::at can be used for extracting characters from string. Here is the simple code for the same.
G e e k s F o r G e e k s
This article is contributed by Pushpanjali Chauhan. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Find the character in first string that is present at minimum index in second string
- Check if a string can become empty by recursively deleting a given sub-string
- Check if a string can be formed from another string using given constraints
- std::string::append vs std::string::push_back() vs Operator += in C++
- std::string::remove_copy(), std::string::remove_copy_if() in C++
- std::string::replace , std::string::replace_if in C++
- std::string::replace_copy(), std::string::replace_copy_if in C++
- std::string::find_last_not_of in C++
- string find in C++
- Tokenizing a string in C++
- getline (string) in C++
- std::string::clear in C++
- std::string::erase in C++
- std::string::insert() in C++
- std::string::compare() in C++