Click here to Skip to main content
15,887,988 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
the c++ code not running but it compiled with no error in visual studio
after press run the dos window open for just second and close
i used dev -c++ but also the same problem

What I have tried:

i turned off the antivirus but it didn't work
Posted
Updated 19-Oct-17 10:55am
v2
Comments
Patrice T 19-Oct-17 16:57pm    
Because you made a mystery mistake in your mystery code.
You did it wrong !

There are any number of reasons for this. What I do when this kind of thing happens is I set a breakpoint on the first statement in the main function and then run the code in the debugger and step through it to see what happens. That's all I can advise at this point since I can't see your code.
 
Share this answer
 
(Wild guess) You wrote a console application, something like
C++
#include <iostream>
int main()
{
  std::cout << "hi there!" << std::endl;
}

In such a case the behaviour you described is the correct one: the application starts, produces the output and (quickly) terminates. If you need a chance to see the output you have to stop its execution (at least for a while). You can, for instance, pause it with a synchrounous input request:
C++
#include <iostream>
int main()
{
  std::cout << "hi there!" << std::endl;
  std::cin.get(); // waits for input
}

Alternatively, you might launch your console application from the command prompt.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900