Solved

Convert char to const char * c++

Posted on 2013-05-31
2
3,790 Views
Last Modified: 2013-05-31
How can i convert a char to const char* in c++
When i try to convert it i get this error:
invalid conversion from char to const char *
0
Comment
Question by:HaniDaher
2 Comments
 

Accepted Solution

by:
HaniDaher earned 0 total points
ID: 39210227
we can use std::string(size_t , char ) constructor
string a = std::string(1 , str[0]);

Thank you,
well you are most welcome.
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 39210236
JFI: I would propose to do it directly without creating a copy, that's faster:

string a(1 , str[0]);
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question