Solved

Convert char to const char * c++

Posted on 2013-05-31
2
3,754 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now