Solved

Convert char to const char * c++

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

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

758 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

18 Experts available now in Live!

Get 1:1 Help Now