Handling text is an important aspect of software development. The C++ language has two methods of handling text: C-Style strings and C++ Strings. Converting between the two is often necessary when using functions from older libraries. If you need to convert a C++ String into a C-Style string, one approach is to extract the individual characters from the C++ String and place them one at a time into the C-Style string.
Things You'll Need
- C++ Compiler, such as GCC
- C++ Integrated Development Environment, such as Eclipse CDT
Create a new C++ source code file.
Import the C++ String library by writing the following line at the top of your source code:include <string>
Create a new C++ String in a source code file by writing a line like this:
string str ("C++ String");
Define a character type to hold the characters in the C++ String:
Assign a character to temp by using the  operators of the C++ String. The number between the square brackets will select the character at that location in the C++ String, with the first character starting in index 0. In the example below, the fifth character of string str ('S') is assigned to temp.
temp = str;
- Photo Credit Ablestock.com/AbleStock.com/Getty Images
How to Read a String in C
The C programming language doesn't provide an actual string data type. In C, a string is emulated by an array of characters...
How to Split a String in C
ANSI C is one of the oldest and most widely used lower level programming languages still in use by modern, professional programmers....
How to Convert INT to String in Java
Converting an integer to a string is a common practice when programming. For some application processes, it's necessary to manipulate the format....
How to Convert Hex to Binary in Visual Basic
Visual Basic can change from one number base to another with a bit of manipulation in some short lines of code. Numerous...
How to Convert Double to String C++
C++ handles a variety of conversions between number types and strings using the iostream class and the put-to operator "<<." The iostream...
How to Convert a String to an INT C
Many C++ programs need to present data in a human-readable format. The easiest way to do this is to convert numeric data...
How to Convert Date to String in SQL
Structured Query Language (SQL) provides you with the tools to update, delete, select and edit your table's data. SQL is similar to...