Category: std::string
How to remove Substrings from a String in C++
In this article we will discuss how to remove single or multiple sub strings from a given string. std::string class provides a member function string::erase() to remove some characters from a given position i.e. Advertisements string& erase (size_t pos = 0, size_t len = npos); It accepts a position and length of characters to be …
C++ : Case-insensitive string comparison using STL | C++11 | Boost Library
In this article we will discuss different ways to Compare strings in case insensitive manner. Suppose we have two strings i.e. Advertisements std::string str1 = “Hi This is SamPle”; std::string str2 = “hi this is sample”; Both the above strings should be equal if we compare them in case insensitive manner. Let’s see how to …
C++ : Case-insensitive string comparison using STL | C++11 | Boost LibraryRead More
C++ : strcmp() Tutorial | Comparing strings
In this article we will discuss how to compare strings using strcmp(). strcmp() is a C Library function that helps to compare two strings i.e. char * Advertisements int strcmp ( const char * firstStr, const char * secondStr ); It iterates over both strings i.e. firstStr & secondStr in parallel and compares each character …
Convert int to String in C++
In this article, we will learn about three different ways to convert an integer to a string in C++ i.e. Using to_string() function Using stingstream Using Boost’s lexical_cast() function. Let’s discuss them one by one. Convert int to string using to_string() C++ provides a function std::to_string() for converting values of different types to string type. …
C++ – Check if string contains a character
In this article, we will learn about three different ways to check if a string contains a character or not. Check if a string contains a character using string::find() In C++, the string class provides different overloaded versions of function find() to search for sub-strings or characters in the string object. In one of the overloaded versions, …
Convert float to string in C++ (3 Ways)
In this article, we will learn about three different ways to convert a float to a string in C++ i.e. Using std::to_string() function Using std::stingstream Using Boost’s lexical_cast() function. Let’s discuss them one by one. Convert float to string using to_string() C++ provides a function std::to_string() for data type conversion. We can use this to …
Convert double to string in C++ – (3 ways)
In this article, we will learn about three different ways to convert a double to a string in C++ i.e. Using std::to_string() function Using std::stingstream Using Boost’s lexical_cast() function. Let’s discuss them one by one. Convert double to string using to_string() C++ provides a function std::to_string() for data type conversion. We can use this to …
Convert Long to String in C++ | (3 ways)
In this article, we will learn about three different ways to convert a long to a string in C++ i.e. Using to_string() function Using stingstream Using Boost’s lexical_cast() function. Let’s discuss them one by one. Convert long to string using to_string() C++ provides a function std::to_string() for converting values of different types to string type. …
Check if String is Empty in C++
In this article, we will discuss different ways to check if a string is empty or not in C++. Table of Contents Check if String is Empty in C++ using string::empty() Check if String is Empty in C++ using string::size() Check if String is Empty in C++ using string::length() Check if String is Empty in …
Check if strings are equal in C++
This article will discuss different ways to check if two strings are equal in C++. Table Of Contents Check if strings are equal using == operator Check if strings are equal using compare() function Check if strings are equal using the equal() function Check if strings (char *) are equal using strcmp() Check if strings …