Can't run program

Pages: 12
Oct 12, 2009 at 9:39am
Hi,
I'm a beginner having problems with writing my hello world program.
I am using the tutorial on this site, because it seems easy to understand.
Allthough the coding I have made is the exact same as in the tutorial I can't run the program.

The error I get is:
Unable to start program 'C:\users\morten\documents\visual studio 2008\projects\test\debug\test.exe
The file does not exist

I am using Microsoft Visual C++ 2008 Express Edition.

Can anyone tell me what the error is?
Oct 12, 2009 at 10:32am
Have you built test.exe in advance?
Oct 12, 2009 at 11:13am
Nope, just got the program over night so trying to learn the codes.

Can you tell me how to?
Oct 12, 2009 at 12:23pm
Press F7 to compile your code and then ctrl+F5 or just F5 to run your program.
Oct 12, 2009 at 6:44pm
Still doesn't work..

Now it says:
The debugger does not support debugging managed and native code at the same time on this platform.
Oct 12, 2009 at 6:48pm
Which project template did you started with? On VC++ you should always start with an empty project
Oct 12, 2009 at 7:31pm
I started with the CLR Class Library..
Oct 12, 2009 at 7:36pm
I suggest you:
- create a new Empty Project
- copy/paste your code -or move the files- into the new project
- delete the old project
- compile the new project, it should work
Oct 12, 2009 at 7:58pm
Tryed it and it worked, just got a small problem that the program is shotting down imidiately after printing the text.

Have looked in the other topic but none of the solusions seem to work correctly, the program is still shotting down..
Oct 12, 2009 at 8:01pm
Here is the article: http://www.cplusplus.com/forum/articles/7312/
Are you using cin >> before the program end?
Oct 12, 2009 at 8:12pm
Nope, my code looks exactly like this:
http://www.cplusplus.com/doc/tutorial/program_structure/

I have tried some different solutions shown in the article you are linking to, but they don't seem to work..
Oct 12, 2009 at 8:16pm
This should work:
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <limits> // for numeric_limits
using namespace std;

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

  cin.ignore ( numeric_limits<streamsize>::max(), '\n' ); // "The Standard Way" in the article
  return 0;
}
Oct 12, 2009 at 8:23pm
Yay it's working..
Thanks mate.. :)
Oct 12, 2009 at 9:59pm
I just ran into the same problem again during this tutorial:
http://www.cplusplus.com/doc/tutorial/basic_io/

The program is closing as soon as I press enter, is there a way that I can "delay" the closing of the program so I can se the program after pressing enter?
Oct 13, 2009 at 12:29pm
That's the cin >> problem, it leaves the \n character in the stream.
With cin you should use getline: http://www.cplusplus.com/forum/articles/6046/
Oct 13, 2009 at 12:39pm
so instead of cin >> i should type getline(cin, )?
Oct 13, 2009 at 12:52pm
To get a string, you use getline(cin, mystr); //mystr is a string
You can also use getline() to get an integer or character, but no directly, you must use an alternative method (http://www.cplusplus.com/forum/articles/6046/ shows you how to get all 3 types of input that can handle invalid input).
Oct 13, 2009 at 12:58pm
Yes, but only if you are using string objects from the string class <string>

Otherwise use cin.getline();
Oct 13, 2009 at 9:15pm
It doesn't seem to work..

The window is still closing after I press enter..

Instead of cin >> i have written cin.getline but it is telling me there are some error in the code..

I find that rather confusing?
Oct 13, 2009 at 9:29pm
What is your code with getline?
Pages: 12