[Dev-C++] RE : [c-prog] what's wrong with the code
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Dawood V. <da...@ku...> - 2003-08-12 01:39:49
|
Subject: RE : [c-prog] what's wrong with the code
I tried "using namespace std;" it still gives me error.
I tried: string p(1,ch); But it does not serve the purpose of the
code, Basically, I want to enter one character at the back of the string
at one time.
Lastly, it simply does not compile: below is the same code, I produce
again, with the type of compile time error it gives. The details about the
errors are in the comments of the code just below the line which is
responsible for the error. I need two things. Explanation and alternative.
#include <iostream.h>
#include <stdlib.h>
#include <string>
int main()
{
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_template<false,0>
>' requested
*/
p.push_back(ch);
/* for the above line the following is the error it gives me :
no matching function for call to
`basic_string<char,string_char_traits<char>,__default_alloc_template<false,0>
>::push_back (char &)'
*/
system("PAUSE");
return 0;
}
|