I just worked out how to use strings a little thanks to this forum. I was wondering though, if it is possible to have a string array(?) accept spaces?
For instance:
I've included the string library. Now, I declare the array "items".
string items[20];
Can I have it so that a "cout<<items[0];" line will accept the words BLUE CHEESE? I noticed that it will accept one word but not two words separated by spaces when put in a while loop.
I'm not using std::cin.
Could you give me some example code on how to use this getline(std::cin, myVariable)?
Sorry. I'm completely new to programming.
Can I have it so that a "cout<<items[0];" line will accept the words BLUE CHEESE?
EDIT: misunderstanding about what items was. However it doesn't change that cout is not the problem. The problem was filling the strings. Spaces in the string will not affect cout.
cout isn't the problem. You are attempting to send 1 of the stringsto the output stream because you are using the operator[] to access the first element of the array.
Take bluezor's first piece of advice and stick with std::string. Using a char buffer can cause array overflow which is undefined behavior. It is much safer to use std::string with getline. However, if you really want to there is a version of getline that takes a char*.