convert string to char

How do I covert string abc to char?

#include <iostream>
#include <string>
using namespace std;

char letter;

int main ()
{
string abc ("This is an example phrase.");
cout << abc << endl;

// output This is an example phrase.

cin>>abc; //input qwerty
cout<<abc << endl;

//output qwerty

abc.erase (1);
cout << abc << endl;

//Output q

/*what code do I put here to convert abc string holding value of q
to char letter? Do I need additional header files to support this?*/

cout<< letter; //want output to be q from abc string


cin.ignore(256,'\n');//Code so program output does not flash off screen on Bloodshed Dev C++ compiler.

cin.get();//Stops program until enter key is pressed.

return 0;
}
Use string's operator[] like so:

some_string[0]; //this is the first character in the string
Nah, you don't need any more header files libs or any of that mumbo jumbo. Check this out:

http://www.cplusplus.com/reference/string/char_traits/

Basically a string is a dynamic array of chars so I guess the answer to your question is nothing? If you need to pass the string to a function that doesn't have a definition to handle strings then that's where we use these babies:

http://www.cplusplus.com/doc/tutorial/pointers/
Thank you!
closed account (4Gb4jE8b)
well answered computer geek!
Topic archived. No new replies allowed.