0

Hi,

Im getin the following error when i try the code below..Anyone tell me whats wrong?? (name is defined in animal class)..

52 C:\Dev-Cpp\oopAssign1.cpp no match for 'operator>>' in 'std::cin >> name'

void Animal::arrayDisplay(){
     
     string name[3];
  
     cout <<"Input 3 names:" << endl;
     
     for(int i=0; i<3; ++i){
        cin >> name;
        name[i] = name;
        cout << "name[i]" <<endl; }
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by oggiemc
0

The variable "name" is an array of std::string. As such, the actual variable called "name" is a pointer to std::string. Since it's a pointer to std::string, you can't input to it directly. You need to input to an element of the name array:

std::string array[10];
for (int i = 0; i < 10; ++i) {
  cin >> array[i];
}

Edited by Fbody: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.