<hn*****@gmail.comwrote in message
news:11*********************@k70g2000cwa.googlegro ups.com...
#include <iostream/* declares 'std::cout' */
#include <ostream /* declares 'std::endl' */
int main()
{
char *test = "hello";
Should be:
const char *test = "hello";
Without the 'const', the compiler would allow you
to modify the literal via the pointer. But modification
of a string literal produces undefined behavior, where
Bad Things can happen.
std::cout << *test << std::endl;
return 0;
}
the result of out put is h; only the first character.
That's exactly what your program told the computer to do.
Read about 'pointer dereference'.
>But what I want
is the whole string. How to do that?
std::cout << test << '\n';
An aside: in C++, instead of using 'C-style' strings
(zero terminated arrays of characters), I recommend
using the std::string type (declared by the header
<string>) instead.
-Mike