• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

Question on MS Visual C++

Joined
6/18/08
Messages
3
Points
11
Hi all,

I am trying to self-learn fundamental of C++, can you guys please enlighten me on why some codes can not be executed on MS visual C++?

For instance, when I try to run the following program, it gives me an error message "Unable to start program... the system can not find the path specified."

#include <iostream.h>
int main()
{
cout << "Hello World!\n";
return 0;
}

Thanks,
Zichuan
 
Try this version. I have added a specification of the "std" namespace, as well as a proper include for the system library "iostream"

C++:
[COLOR=#0066ff][FONT=Courier New]#include <iostream>[/FONT][/COLOR]
[COLOR=#0066ff][FONT=Courier New]int main()[/FONT][/COLOR]
[COLOR=#0066ff][FONT=Courier New]{[/FONT][/COLOR]
std::[COLOR=#0066ff][FONT=Courier New]cout << "Hello World!\n";[/FONT][/COLOR]
[COLOR=#0066ff][FONT=Courier New]return 0;[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]}
[/FONT][/COLOR]
 
try using the code doug posted, but without the "std::" and with a line after the include statement saying
using namespace std;

it shouldn't make much of a difference, but it should work! at least it does onmy ms visual c++
 
In various books and websites you will find C++ code that work in modern C++ compilers.
That applies especially to MS VC++ which two versions ago started to be much more compliant with the standard.
The notion of a Std, ie "Standard" namespace led some implementors to think that it should be included as a default.
I could explain namesapces, but google or any decent modern book will do it for you.
 
Thanks you all for helping, I have modified the codes as cstassen suggested, and it gives me the same error message. Can you guys please advise further?

#include <iostream>

int main()
{
cout << "Hello World!\n";

using namespace std;

return 0;
}
 
try using the code doug posted, but without the "std::" and with a line after the include statement saying
using namespace std;

Move the line you added higher up in the program:

C++:
[COLOR=blue][FONT=Courier New]#include[/FONT][/COLOR][FONT=Courier New] [COLOR=#a31515]<iostream>[/COLOR][/FONT]
[COLOR=blue][FONT=Courier New]using[/FONT][/COLOR][FONT=Courier New] [COLOR=blue]namespace[/COLOR] std;[/FONT]
  
[COLOR=blue][FONT=Courier New]int[/FONT][/COLOR][FONT=Courier New] main()[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New]cout << [COLOR=#a31515]"Hello World!\n"[/COLOR];[/FONT]
 
[COLOR=blue][FONT=Courier New]return[/FONT][/COLOR][FONT=Courier New] 0;[/FONT]
[FONT=Courier New]}[/FONT]
Anyway, you should
1. get a book,
2. google the error messages you have (someone else has always had the same problem), and
3. look in the Visual C++ Help for a tutorial on how to write a program. That will definitely work.

Now that I think of it, in all likelihood you probably created the wrong type of project in Visual C++. You want a Win32 Console Application. It should be checked off as an empty project when you get to that point in the process. Again, read the tutorials.
 
Hi Doug,

For some reason, it still won't runned. However, the following code which I found at http://www.vtc.com/products/c_plusplus_fundamentals.htm works fine. And the syntax is quite different.

#include"stdafx.h"
usingnamespace System;
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
return 0;
}

This looks a lot like C# so, I might be inclined to think that this is how managed C++ looks like or some kind of M$ version outside of standard C++.
 
Back
Top