Is it like this ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream.h>
#include <iomanip.h>
#include <string>
using namespace std;
class CAT
{
public:
CAT() {}
~CAT() {}
void Setname(string name) { Name=name;}
string Getname(){ return Name;}
private:
string Name;
};
int main()
{
CAT Litter[3];
int i;
string name;
for (i = 0; i < 3; i++)
{
getline(cin,name);
Litter[i].Setname(name);
}
for (i = 0; i < 3; i++)
{
cout<<"Cat #"<<i+1<<": ";
cout<<Litter[i].Getname()<<endl;
}
return 0;
}
|
But i cannot compile it .
i wan to pass it to a function. Den return with a function.
Here are the compilation errors.
D:\Unimas\Sem 1 0910\software enginrng\Project\testing\test.cpp(26) : error C2780: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : expects 3 arguments - 2 p
rovided
c:\program files\microsoft visual studio\vc98\include\string(149) : see declaration of 'getline'
D:\Unimas\Sem 1 0910\software enginrng\Project\testing\test.cpp(26) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce template argument
for 'class std::basic_istream<_E,_Tr> &' from 'class istream_withassign'
D:\Unimas\Sem 1 0910\software enginrng\Project\testing\test.cpp(26) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce template argument
for 'class std::basic_istream<_E,_Tr> &' from 'class istream_withassign'
D:\Unimas\Sem 1 0910\software enginrng\Project\testing\test.cpp(26) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce template argument
for 'class std::basic_istream<_E,_Tr> &' from 'class istream_withassign'
D:\Unimas\Sem 1 0910\software enginrng\Project\testing\test.cpp(32) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (
or there is no acceptable conversion)