2012-02-16 2 views
1

Это действительно простая программа, и я не знаю, что у меня получилось. Я посмотрел онлайн, и я не смог найти ничего полезного. С моей getline (cin, movieName) что-то не так, но я не знаю, что.Ошибка Getline - «не удалось вывести шаблонный аргумент»

//This program will calculate a theater's revenue from a specific movie. 
#include<iostream> 
#include<iomanip> 
#include<string> 
using namespace std; 

int main() 
{ 
    const float APRICE = 6.00, 
       CPRICE = 3.00; 

    int movieName, 
     aSold, 
     cSold, 
     gRev, 
     nRev, 
     dFee; 

    cout << "Movie title: "; 
    getline(cin, movieName); 
    cout << "Adult tickets sold: "; 
    cin.ignore(); 
    cin >> aSold; 
    cout << "Child tickets sold: "; 
    cin >> cSold; 

    gRev = (aSold * APRICE) + (cSold * CPRICE); 
    nRev = gRev/5.0; 
    dFee = gRev - nRev; 

    cout << fixed << showpoint << setprecision(2); 
    cout << "Movie title:" << setw(48) << movieName << endl; 
    cout << "Number of adult tickets sold:" << setw(31) << aSold << endl; 
    cout << "Number of child tickets sold:" <<setw(31) << cSold << endl; 
    cout << "Gross revenue:" << setw(36) << "$" << setw(10) << gRev << endl; 
    cout << "Distributor fee:" << setw(34) << "$" << setw(10) << dFee << endl; 
    cout << "Net revenue:" << setw(38) << "$" << setw(10) << nRev << endl; 

    return 0; 
} 

А вот ошибки я получаю:

error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Alloc> &' from 'int' see declaration of 'std::getline' 

error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : expects 3 arguments - 2 provided 
see declaration of 'std::getline' 

error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &&,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Alloc> &' from 'int' 
see declaration of 'std::getline' 

error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &&,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : expects 3 arguments - 2 provided 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(395) : see declaration of 'std::getline' 

ответ

2

Проблема здесь состоит в том, что getline требует std::string (или какой-либо другой тип basic_string) в качестве аргумента, и вы предоставляя int. Как я mentioned in my answer to your previous question, вы должны переключить тип movieName как std::string. Вы также должны соответствующим образом изменить тип своих других переменных (они, вероятно, должны быть float с, если вы умножаете другие значения на float s), и я предлагаю переместить определения до более поздних версий в main, где они фактически используются.

Надеюсь, это поможет!

0

Первое, что я вижу, это movieName объявляется как целое, а не как строка или массив char (строка C). Это, по-видимому, основная проблема, вызывающая множественные ошибки в отношении getline.

Смежные вопросы