Jan 4, 2011 at 3:03am Jan 4, 2011 at 3:03am UTC
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;
}
Jan 4, 2011 at 3:18am Jan 4, 2011 at 3:18am UTC
Use string's operator[] like so:
some_string[0]; //this is the first character in the string
Jan 4, 2011 at 3:33am Jan 4, 2011 at 3:33am UTC
well answered computer geek!