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 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 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...
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 a String to an INT C
In "C," character strings are stored as an array of character codes and manipulated as characters. If your character strings represent whole...
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...