Just a short question and I will be on my way. Why am I getting errors when I try to read in string using the string class? The error I receive is: "no operator ">>" matches these operands/operand types are std::istream >> std::string *"
I am starting to use the class instead of cStrings. Unfortunately, I keep getting errors when I try to read in a string using cin. For example:
void ProcessEditMenuItems( int menu_choice, std::string fname[], std::string lname[],
std::string phone[], std::string bday[] /*char fname[][NAME_LENGTH], char lname[][NAME_LENGTH], char phone[][NAME_LENGTH],
char bday[][NAME_LENGTH]*/ )
{
switch ( menu_choice )
{
case 1:
std::cout << "\nEnter new first name: ";
std::cin >> fname;
break;
case 2:
std::cout << "\nEnter new last name: ";
std::cin >> lname;
break;
case 3:
std::cout << "\nEnter new phone number: ";
std::cin >> phone;
break;
case 4:
std::cout << "\nEnter new birthday: ";
std::cin >> bday;
break;
}
}
The above code works for normal cStrings, but when I change the function declaration and definition to the string class it does not work.
string fnamewould be something like achar fname[19]. so no need of[]for using string in your case. usestring fname[]when you need an array of strings!!! :)cin >> fname[i]will put the input to the 'i'th place of the fname array. You cannot docin >> fnamebecause fname is not a string but an array of strings. (operator>>ofstd::cindoesn't know what to do when the Right Hand Side of the>>operator is an array of strings!! so it should give compilation error.) Still you need to work on how you pass the parameters. i suggest passing them in as pointers or references.