std::string

Convert a string to a vector of chars in C++

In this article, we will discuss different ways to convert a string to a vector of chars in C++. Table Of Contents Method 1: Using Vector’s range constructor Method 2: Using copy() function Summary Method 1: Using Vector’s range constructor Create two iterators pointing to the first, and one past the last characters of string. …

Convert a string to a vector of chars in C++ Read More »

Replace Last Character of a String in C++

In this article, we will discuss different ways to replace last character of a string with another character in C++. Table Of Contents Using subscript operator Using string::replace() function Using string::at() function Using string::substr() Suppose we have a string like this, We want to replace the last character of this string with character ‘X’. The …

Replace Last Character of a String in C++ Read More »

Replace First Character in a string in C++

In this article, we will discuss different ways to replace first character of a string with another character in C++. Table Of Contents Using subscript operator Using string::replace() function Using string::at() function Using string::substr() Suppose we have a string like this, We want to replace the first character of this string with character ‘X’. The …

Replace First Character in a string in C++ Read More »

Replace all occurrences of a character in String in C++

In this article, we will discuss different ways to replace all occurrences of a character from a string with an another character in C++. Table Of Contents Using STL Algorithm std::replace() Using string::replace() and find() Using Iteration Suppose we have a string, We want to replace all the occurrence of character ‘e’ with ‘P’ in …

Replace all occurrences of a character in String in C++ Read More »

Scroll to Top