I'm trying to read a single letter from the beinging of a string that is generated from user input. Though it sounds childishly easy, I think I may seriously have a heart attack from trying to solve this problem. Example code follows:
#include <iostream>
#include <string>
#include <sstream>
#include <stdlib.h>
using namespace std;
int main()
{
string user_input;
string first_letter = user_input[0];
getline(cin, user_input);
cout << first_letter;
return 0;
}
I get an error of "error: invalid conversion from 'char' to 'const char*'" from the compiler. I've tried mainipulating the values to be char array's what feels like 100 times, but I can't assign an array size because I don't know how much text the user is going to put in.
Any help is appreciated.
[EDIT]: I ought to note that whatever variable I assign to be the first letter from the user_input string has to be a string type, I can't use it in other parts of the program if it is a char type.