|
|
![]() |
| Thread Tools | Search this Thread |
#1
| |||
| |||
Converting string to char I am having a small code created in C++. I want to convert string to char. I tried using explicit conversion but that isn't working. It still result in error messages. Is there any other way to convert string to char in C++? |
#2
| |||
| |||
Re: Converting string to char Code: char convertStrToChar(const char *chr) { int i = 0; for(i = 0; *conv[i][1]; i++) { if(strcmp(conv[i][0], chr) == 0) { return (char) conv[i][1]; } } return '\0'; } |
#3
| |||
| |||
Re: Converting string to char You can also something like: Code: string x; const char *p = "Hello"; strcpy(x,p); cout<<x; |
#4
| |||
| |||
Re: Converting string to char The below code can even convert the string "Hello" to char. The "substring" takes certain characters from the given string and converts it into char. Code: string str = "Hello"; char c = (char)str.Substring(3,2); |
![]() |
|
Tags: char, cpp, string, string to char |
Thread Tools | Search this Thread |
|
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Converting Boolean values to string in Java | 27lynx27 | Software Development | 1 | 13-02-2011 03:40 AM |
How to convert string to char array in java? | Baazigar | Software Development | 6 | 10-01-2011 06:36 PM |
Converting a string number into sequence of digits | KAIRU26 | Software Development | 5 | 13-03-2010 04:46 PM |
Converting Char to Int in PHP | GlassFish | Software Development | 4 | 05-03-2010 08:06 PM |
Converting Char value to ASCII number, C++ | Gemstone29 | Software Development | 2 | 22-04-2009 08:30 AM |