This is what I’m trying to do…
char input[4];
cin >> input;
cout << "Input[0]: " << input[0] << "Input[1]: " << input[1] << "Input[2]: " << input[2] << "Input[3] " << input[3]<< "Input[4] " << input[4] <<endl;
However, when I enter “P F” I get an output of this: Input[0]:P Input[1]: Input[2]:(A weird looking square with two zeros on top and a zero and 4 on the bottom) Input[3] Input[4]
Why do I get that weird character instead of F?
cin >>separates inputs by a space, hence when you enterP<space>F, only thePis accepted intoinput, andFis queued for the nextcin >>.Thus after that
cin >> inputline, yourinputwill look likePerhaps you want to use
cin.getline:(Or better, use
std::stringwhich has flexible string length.)