basic programing - printing a variables value [c++]

Started by
2 comments, last by spooky_paul 16 years, 11 months ago
hi, i have made a little hello world console app. here is the code: #include <stdio.h> float myVar = 1; int main () { printf( "hello world" ); getchar(); return 0; } what i want now is to print the value of myVar instead of "hello world". how do i do that? thanks
Advertisement
#include <iostream>....int i = 10;float f = 3.14;std::cout << "Hello world" << "  " << i << " " << f << std::endl;


printf is C, so it's not generally recommended in C++;

int i = 10;printf("%d", i);
well for starters, use the cout function instead of printf

the syntax is

std::cout<<"string here";

or to display a variable you would do

std::cout<< variable name <<;
Thanks m8s! :)

This topic is closed to new replies.

Advertisement