Solved

Convert char to const char * c++

Posted on 2013-05-31
2
3,887 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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…
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.

726 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