
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7197 Articles for C++

434 Views
In this section, we will see how to convert an integer to a string.The logic is very simple. Here we will use the sprintf() function. This function is used to print some value or line into a string, but not in the console. This is the only difference between printf() and sprintf(). Here the first argument is the string buffer. where we want to save our data.Input: User will put some numeric value say 42 Output: This program will return the string equivalent result of that number like “42”AlgorithmStep 1: Take a number from the user Step 2: Create an ... Read More

7K+ Views
Tokenization refer to the process of breaking a string based on certain delimiters such as spaces, commas, semicolons, or any other character. Mostly white spaces are used as delimiters to tokenize strings. In this article, we will discuss all the ways tokenize a string in C++. For example, if we have a string like "Hello, World! Welcome to Tutorialspoint.", we can tokenize it like this: string str = "Hello, World! Welcome to Tutorialspoint."; tokens = {"Hello", "World", "Welcome", "to", "Tutorialspoint"}; Tokenizing a String in C++ In C++, we can tokenize a string using various methods. Here are ... Read More

155 Views
There is no one elegant way to iterate the words of a C/C++ string. The most readable way could be termed as the most elegant for some while the most performant for others. I've listed 2 methods that you can use to achieve this. First way is using a stringstream to read words separated by spaces. This is a little limited but does the task fairly well if you provide the proper checks. For example, >Example Code Live Demo#include #include #include #include using namespace std; int main() { string str("Hello from the dark side"); ... Read More

145 Views
In this section, we will see what is the at a () function in C++. The at() function is used to access the character at a given position.In this program, we will iterate through each character using at a () function and print them into different lines.Example Code Live Demo#include using namespace std; main() { string my_str = "Hello World"; for(int i = 0; i

88K+ Views
In this section, we will see how to remove some characters from a string in C++. In C++ we can do this task very easily using erase() and remove() function. The remove function takes the starting and ending address of the string, and a character that will be removed. // Input String = "Hello TutorialsPoint" Char = 'o' // Output String = "Hell TutrialsPint" Algorithm to Remove Certain Characters from a String Here is the algorithm to remove certain characters from a string in C++: Step 1: Take a string and a character to be removed ... Read More

357 Views
In this section, we will see how to reverse a string very quickly using C++. For reversing there is a built-in function in the algorithm library, called reverse(). This function takes the beginning and the ending pointer of a container, then reverse the elements.Input: A number string “Hello World” Output: “dlroW olleH”AlgorithmStep 1:Take a string Step 2: reverse it using reverse() function Step 3: Print the result. Step 4: EndExample Code Live Demo#include #include using namespace std; main() { string my_str = "This is a string to be reversed"; cout

3K+ Views
Here we will see how to map enum type data to a string in C++ There is no such direct function to do so. But we can create our own function to convert enum to string. We shall create a function that takes an enum value as the argument, and we manually return the enum names as a string from that function. First of all, let us understand what is an enum in C++. What is an Enum in C++? Enum is a user-defined datatype in C++ that is used to assign names to integer values. For example, you ... Read More

9K+ Views
The STL library in C++ provides various inbuilt functions and methods to manipulate strings, such as converting them to lower case or upper case. In this article, we will learn all the approaches to convert a std::string to lower case in C++. First of all, let's understand the problem statement. In this problem, you are given a string as input and you need to convert it to lower case. The string may contain any type of characters such as letters, digits, and special characters. For example: // Input String std::string str = "Hello World! 123 @ TutorialsPoint"; // ... Read More

557 Views
Enum is a user-defined datatype in C++ that is used to assign names to integer values. For example, you can use an enum to represent the days of the week from 0 to 6, where 0 represents Sunday, 1 represents Monday, and so on. When you try to access a value of an enum, it will only return an integer value. In this article, we will learn how to convert an enum type variable to a string type variable in C++, so that we can easily display the enum value as a string. Example of Enum: enum color ... Read More

1K+ Views
In this section, we will see how to convert C++ string (std::string) to const char* or char*. These formats are C style strings. We have a function called c_str(). This will help us to do the task. It returns a pointer to an array that contains a null-terminated sequence of characters (i.e., a C-string) representing the current value of the string object.Following is the declaration for std::string::c_str.const char* c_str() const;This function returns a pointer to an array that contains a null-terminated sequence of characters (i.e., a C-string) representing the current value of the string object. If an exception is thrown, ... Read More