C convert from 1 char to string

0 votes

I simply need to cast one character to string. 

The inverse method is as easy as str[0].

The following suggestions did not work for me:

char c = 34;
string(1,c);
//this doesn't work, the string is always empty.

string s(c);
//also doesn't work.

boost::lexical_cast<string>((int)c);
//also doesn't work.

Jun 29, 2022 in C++ by Damon
• 4,960 points
804 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In C++

0 votes
1 answer

How to convert string to char array in C++?

Simplest way I can think of doing ...READ MORE

answered Jun 20, 2022 in C++ by Damon
• 4,960 points
4,805 views
0 votes
1 answer

Easiest way to convert int to string in C++

C++ adds std::stoi (and variants for each numeric type) and std::to string, which are the C equivalents of atoi and itoa but expressed in terms of std::string #include <string> std::string s = std::to_string(42); Is therefore ...READ MORE

answered Jun 1, 2022 in C++ by Damon
• 4,960 points
1,010 views
0 votes
1 answer

Easiest way to convert int to string in C++

std::stoi (and variations for each numeric type) ...READ MORE

answered Jun 15, 2022 in C++ by Damon
• 4,960 points
849 views
0 votes
0 answers

How to convert a char array to a string?

Converting a C++ string to a char ...READ MORE

Jul 14, 2022 in C++ by Nicholas
• 7,760 points
354 views
0 votes
1 answer

How can I convert a std::string to int?

There are some new convert methods in C++ that convert std::string to a numeric type. As an alternative to str.c str() atoi(str.c str()) atoi(str.c str() you can make use of std::stoi std::stoi ...READ MORE

answered Jun 1, 2022 in C++ by Damon
• 4,960 points
492 views
0 votes
0 answers

Reverse a number without converting it to string in C++

I'm attempting to write a programme in C++ to reverse a number. It works well with numbers like 1234, but when I try to enter a number like 5430, it displays 345, and the same with numbers that begin with zero, such as 0234, which displays 432. Could someone please explain how to deal with zeros at the beginning and end of a sentence? I simply need to save the number without converting it to a string. #include<iostream> using namespace std; int main(){ ...READ MORE

Jun 30, 2022 in C++ by Nicholas
• 7,760 points
408 views
0 votes
1 answer

casting int to char using C++ style casting [duplicate]

Even though the precision is lost, yo ...READ MORE

answered Jun 13, 2022 in C++ by Damon
• 4,960 points
15,970 views
0 votes
0 answers

dynamic_cast and static_cast in C++

 I'm perplexed by the dynamic cast keyword in C++. struct A { virtual ...READ MORE

Jul 15, 2022 in C++ by Nicholas
• 7,760 points
349 views
0 votes
1 answer

setuptools: build shared libary from C++ code, then build Cython wrapper linked to shared libary

There is a seemingly undocumented feature of setup that ...READ MORE

answered Sep 11, 2018 in Python by Priyaj
• 58,090 points
493 views
0 votes
1 answer

setuptools: build shared libary from C++ code, then build Cython wrapper linked to shared libary

There is a seemingly undocumented feature of setup that ...READ MORE

answered Sep 21, 2018 in Python by Priyaj
• 58,090 points
2,138 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP