C++ problem

michael michael8110 at terra.com.br
Sat Aug 7 01:05:48 PDT 2004


Daniel,thanks a lot,in fact using 'string' did it.Björn,very nice to read  
you again,i still have to look at your message more closely,but what is  
really difficult for me to understand at this point is why
#include<iostream>
using namespace std;
int main()
{char a[20]="citroen";
cout<<a;
return 0;
}

produces
-- 
   michael ~ # ./a.out
citroen

and

#include<iostream>
using namespace std;
class car
{public:
char itsName[20];
};

int main()
{car c;
c.itsName[20]="citroen";
cout<<c.itsName;
return 0;
}

returns this error message

   michael ~ # g++ ./test2.cpp
test2.cpp: In function `int main()':
test2.cpp:12: error: invalid conversion from `const char*' to `char'  
(ISN'T it the same to write char a[20]="citroen"; and  
c.itsName[20]="citroen"; since itsName[20] is a char in the class  
declaration?I tried using string,as Daniel and you suggested and  
everything worked fine,but i still would like to see through this.Thanks  
again.

Using Opera's revolutionary e-mail client: http://www.opera.com/m2/



More information about the lfs-chat mailing list