View Single Post
  #2 (permalink)  
Old September 25th, 2004, 02:35 PM
davekw7x davekw7x is offline
Authorized User
 
Join Date: Feb 2004
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try this:

Code:
#include <iostream>
using namespace std;

int main()
{
  char hello[] = "Hello";

  char *chpoint = hello;

  cout << "First with cout:" << endl;
  cout << "Here's cout << chpoint        : " << chpoint << endl;
  cout << "Here's cout << (void *)chpoint: " << (void *)chpoint << endl;

  printf("\n\nNow, with printf():\n");
  printf("Here's chpoint with printf(%%s): %s\n", chpoint);
  printf("Here's chpoint with printf(%%p): %p\n", chpoint);

  return 0;
}

if you use cout with a variable of type char *, it is designed to print a c-style string.

If you want to print the value of a pointer, cast it to void *.

This works for me, but I don't know what type of machines you have and whether it will work for them.

Regards,

Dave
Reply With Quote