0

I've been attempting to run some easy hello world programs on my command prompt in c++ and c# but after I compile them and attempt to run the .exe files the command jumps a line like it's going to output something, but never does. The cursor continues to blink after I try to run it but nothing happens after that. If I try using "ctrl+c" to close the command prompt, it doesn't work either. I'm not sure what's causing this to occur. I'm running windows 8.1. The C# code was compiled using csc and the C++ code was compiled using g++. The code is shown below:

hello.cpp:

#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
    cout << "hello" << endl;
    getchar();
}

hello.cs:

using System; 
namespace HelloWorldApplication{
   class HelloWorld{
      static void Main(string[] args){

         Console.WriteLine("Hello World");
         Console.ReadKey(); 
      }
   }
}
Cate
  • 1,227
  • 2
  • 9
  • 7
  • You could leave out the `getchar` and `ReadKey` calls, you know. Tip: Ctrl+Break is a slightly stronger signal than Ctrl+C. – Cheers and hth. - Alf Mar 27 '16 at 07:52
  • That wouldn't do anything, probably. This is happening regardless of what code is compiled and run. I just gave the example code for the things I've just recently tried to run. Thanks for the ctrl+space option though. – Cate Mar 27 '16 at 07:56
  • Also I wanted to add that It's not the first time I've written code before on this computer and the code with the getchar() function worked fine. I've been using getchar in my code for a while without problems. – Cate Mar 27 '16 at 07:59
  • 1
    One "popular" cause has been the use of Avast anti-virus: [Running my C++ code gives me a blank console](http://stackoverflow.com/questions/33690697/running-my-c-code-gives-me-a-blank-console) – Bo Persson Mar 27 '16 at 08:20
  • Oh my god it's this again. It's funny because I apparently had the same problem a few months ago and I upvoted that exact question you linked. Stick your comment in an answer and I'll give you a checkmark. – Cate Mar 27 '16 at 08:24

0 Answers0