Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 03-09-2009
Member
 
Join Date: Aug 2009
Posts: 98
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++?
Reply With Quote
  #2  
Old 03-09-2009
Member
 
Join Date: May 2008
Posts: 2,008
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';
}
This code converts string to character.
Reply With Quote
  #3  
Old 03-09-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Converting string to char

You can also something like:

Code:
string x;
const char *p = "Hello";
strcpy(x,p);
cout<<x;
Reply With Quote
  #4  
Old 03-09-2009
Member
 
Join Date: May 2008
Posts: 685
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);
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Converting string to char"
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


All times are GMT +5.5. The time now is 02:25 AM.