RE: [Dev-C++] RE : [c-prog] what's wrong with the code
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <iv...@em...> - 2003-08-12 14:54:41
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Dawood Vora
> Sent: Tuesday, August 12, 2003 4:21 AM
> To: Dev C++
> Subject: [Dev-C++] RE : [c-prog] what's wrong with the code
>
>
> Subject: RE : [c-prog] what's wrong with the code
>
> I tried "using namespace std;" it still gives me error.
> #include <iostream.h>
#include <iostream>
But you do not use any facilities of <iostream> in your code.
> #include <stdlib.h>
Better: #include <cstdlib>
> #include <string>
>
>
> int main()
> {
using namespace std;
> char ch = 'z';
> string p = ch;
> /* for the above line the following is the error it gives me :
> conversion from `char' to non-scalar type
> `basic_string<char,string_char_traits<char>,__default_alloc_te
> mplate<false,0>
> >' requested
> */
The above line is wrong. There is no string constructor taking a char as an
argument.
So your code becomes:
#include <cstdlib>
#include <string>
int main()
{
using namespace std;
char ch = 'z';
string p;
p.push_back(ch);
system("PAUSE");
return 0;
}
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
|