CRAZY STRING OUTPUT
Write your question here.
Why does my output look something like this?
Hello, □nK
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
// hello.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
#include "stdafx.h"
#include <string>
using namespace std;
int main(void)
{
string name = "David";
printf("Hello, %s\n", name);
}
|
printf() cannot output std::strings. It's a function inherited from C, and C has no knowledge of C++ data types.
Thank you very much. I changed the printf statement to:
cout << "Hello, " << name << "\n";
It works.
Topic archived. No new replies allowed.