Solved

Convert char to const char * c++

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

  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 …
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

729 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