1

I have written a simple hello world program in c++ to make sure it wasn't a programming error that was causing my difficulties. If you would like to check over the program:

#include "stdafx.h"
#include <iostream>
int main()
{
std::cout << "Hello, World\n";
std::cin.ignore();
return 0;
}

Anyways, when I open up a program that I made months ago. (I recently started learning again) and run that program it outputs as should. When creating a new program from scratch the program builds and opens up a console window but remains at a blank screen. I believe this is the fault of the IDE and I am missing a setting somewhere.

New Program:

#include "stdafx.h"
#include <iostream>
int main()
{
std::cout << "Hello, World\n";
std::cin.ignore();
return 0;
}

Ctrl+F5: Blank Console

Old Program:

#include "stdafx.h"
#include <iostream>


int doubleNumber(int x) {
return x * 2;
}
int main()
{   
std::cout << "Starting Main" << std::endl;
int y;
std::cout << "Please enter a value you would like to double: ";
std::cin >> y;
y = doubleNumber(y);
std::cout << y << std::endl;
std::cout << "Ending Main" << std::endl;
std::cin.clear();
std::cin.ignore(32767, '\n');
std::cin.get();
return 0;
}

Ctrl+F5: Console as it should be

This problem occurs in all cases of the old and new programs. The programs that I have written today do not display anything to the console, but the programs that I have written in the past perform as inteded.

2 Answers2

1

std::endl will flush the buffered output to the console. The old programs use that. Your 'today' programs do not, so their output is still in the output buffers. Replace your "\n" in your strings with std::endl.

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
0

The solution to my problem was to disable avast antivirus. As simple as this sounds, it is indeed the solution. If you are having this problem I would recommend disabling your antivirus as well.

  • You don't need to completely disable your antivirus, you can add an exclusion for your "\Visual Studio 2015\Projects" folder. – Blastfurnace Nov 17 '15 at 01:51