کد را به شکل زیر هم می توان تغییر داد که نزدیکتر به کد شماست :
string partNumber, partDescript;
int quantity, price;
cout << "Enter the product name: ";
cin >> partNumber;
cout << "Enter the description of the product: ";
cin >>ws;
getline(cin ,partDescript);
cout << "Enter the product quantity: ";
cin >> quantity;
البته یاد آوری می کنم که تابع ()getline پارامتر سومی هم داره که کاراکتر پایان خط را مشخص میکنه و فکر می کنم به صورت پیش فرض '\n' باشه که با تغییر به ' ' مشکل حل می شود و نیازی به هیچ تغییری نیست :
getline(cin ,partDescript, ' ');
مثال :
string s1, s2;
cout << "Enter a sentence (use <space> or <Enter> as the delimiter): ";
cin >> s1;
cout << "You entered: " << s1 << endl;
cout << "Enter a sentence (use <space> as the delimiter): ";
getline(cin, s2, ' ');
cout << "You entered: " << s2 << endl;