Hello. I am currently working with C++ and was instructed by my teacher to convert my "hello world" code to use ascii decimal values instead of human characters for printing hello world to the screen.
would this work?
it's not compiling in Visual Studio.
it says it cannot find myprogram.exe
but it says it successfuly built it, but cannot find the myprogram.exe in the debug folder. Why?
real message:
Unable to start program 'C:\users\Max\documents\Visual Studio 2012\Projects\ascii hello world\Debug\ascii hello world.exe'.
I created a project and the .cpp is within the project. The main point though, is weither or not I was correct with my code. Could you please point me in the right direction?
1: You need to put a semi-colon after each cout statement
2: You are only trying to print numbers, not the ascii value of them
3: Try putting cout << char(the ascii number); instead of cout << "the ascii number"
If you haven't turned off the need for adding the precompiled header, #include "'stdafx.h" , then no. Try adding it as the first line after any comments, and it should compile okay. Mine did..
Oh, and the ascii for capital 'W' is 87, not 119, and capital 'L' is 76
Here is the code I was able to compile, and run, using Visual Studio 2010 C++ Express. The only real change I did, was to comment out the char ascii and int numeric, since you weren't really using them in this program
// Hello World.cpp : main project file.
#include "stdafx.h"
#include <iostream>
usingnamespace std;
int main()
{
//char ascii; // For this program, these two lines were not needed
//int numeric;
cout << char(72);
cout << char(69);
cout << char(76);
cout << char(76);
cout << char(79);
cout << char(32);
cout << char(87);
cout << char(79);
cout << char(82);
cout << char(76);
cout << char(68);
cout << endl; // Just to add a new line after printing the two words
return 0;
}
Oh yeah, I also noticed I accidentally added an apostrophe in #include "'stdafx.h" , that shouldn't have been there. Sorry about that.