overloaded >> operator function not working right

I have an overloaded extraction operator function that allows me to enter information for the member variables for my class. The problem i have is that one of them is a char*. If the is the second in the line it skips the last input. If i make it be last everything works just fine.
I know that it has to do with the last character of the string, the null char but i'm not sure how to make it work. Here's my code for the function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
istream &operator>> (istream &input, Product &aProduct) //stream extraction operator
{
    cout << "Enter the product number: ";
    input >> aProduct.productNumber;
    cout << endl;
    
    cout << "Enter the product description: ";
    input >> aProduct.productDescription;
    cout << endl;
    
    cin.ignore();
    cout << "Enter the unit cost: ";
    input >> aProduct.unitCost;
    cout << endl;
    return input;
}


As you can see i tried cin.ignore but it didn't work. I'm not sure if it is placed in the right place.
Last edited on
Okay new problem with this function. I can't seem to get the input >> aProduct.productDescription to work. ProductDescription is a char*. What happens is when enter the description which is a string of indeterminate length all this stores its the characters up until a space is entered. I know i have to use the get line() function but if i use input.getling() to store the string in a char[] it won't stop so i can enter the info. I know that my code for setting the string works fine. I just don't know how to get this function to let me pass a char[] to the set function for my string.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string str;
    int    productNumber,unitCost;
    char   productDescription[1000];
    cout << "Enter the product number: ";
    cin >> productNumber;
    cout << endl;
    
    cout << "Enter the product description: ";
    getline(cin,str);
    //input >> aProduct.productDescription;
    strncpy(productDescription,str.c_str(),999);
    cout << endl;

    cin.ignore(numeric_limits<int>::max(),'\n');    
    cout << "Enter the unit cost: ";
    cin >> unitCost;
    cout << endl;
}

./a.out
Enter the product number: 888

Enter the product description: 
This is a cat box
Enter the unit cost: 89
Topic archived. No new replies allowed.