1

A number of answers to this exact error have been put upon this website but I am quite the beginner to C++ and Code::Block so i'm afraid I do not understand them.

I have been following a very simple C++ tutorial that started me out with one simple program that I was told to copy and paste into the compiler.

#include <iostream>

using namespace std;

int main()
{
  cout<<"HEY, you, I'm alive! Oh, and Hello World!\n";
  cin.get();

  return 1;
}

I actually did not write any of this code so my own syntax errors cannot be an issue. Basically that means I'm out of ideas for troubleshooting. Any ideas as to why I can't run this?

Okay so saving the file as a .cpp worked for the building, but when my program actually runs nothing appears in the menu that pops up in which, I assume, the text is supposed to appear. Again, I'm decent at troubleshooting but this code has been confirmed to work by thousands of others and there must be something else wrong.

  • 1
    You must set the right path to _include files_ in CodeBlocks. Go to Settings->Compiler and then select the _Search directories_ tab. – polfosol ఠ_ఠ Jun 01 '16 at 06:50
  • 1
    Late last year it was "popular" for Avast anti-virus to [eat the application](http://stackoverflow.com/questions/33690697/running-my-c-code-gives-me-a-blank-console). Could that be it? – Bo Persson Jun 01 '16 at 07:26
  • Omg you were totally right. Thanks alot! (I would have never guessed that) – Casey McDermond Jun 01 '16 at 09:50

2 Answers2

1

Save your file in .cpp format instead of .c format which is default for Code::Blocks. Your workspace(that is the file where you saved this code in) will be renamed to xyz.cpp and you can easily check this fact in the tab.Furthermore, change the cout and cin statements to std::cout and std::cin.

Just to make sure we are on the same page.Goto Settings>>>Compiler.Selected compiler should be GNU GCC compiler. Goto Toolchain Executables tab and autodetect the compiler's installation directory (should be something like CodeBlocks\MinGW).

Ic3fr0g
  • 1,199
  • 15
  • 26
  • I used the same code in CodeBlocks and it works no problems. Try building again and executing. The path for include statements is set automatically by CodeBlocks itself. Just try running the program after reopening CodeBlocks – Ic3fr0g Jun 01 '16 at 06:56
  • Would there be a difference between opening the project as the project file versus the C++ Source File? – Casey McDermond Jun 01 '16 at 07:00
  • Nope, from what I understand its just easier to build a single C++ file instead of the entire project. So, the output should give you a result but the building of a project will take longer. That is the only difference – Ic3fr0g Jun 01 '16 at 07:04
  • Project Name\bin\Debug\Project Name.exe is what is specifically on the program if that helps. I'm not entirely sure what the bin and Debug folders are for. And std:cout and cin did not change anything either – Casey McDermond Jun 01 '16 at 07:09
  • Okay yeah my compiler is the same – Casey McDermond Jun 01 '16 at 07:14
  • See you have created a project and its best to goto CodeBlocks wiki and find out the right way to go about that. But, to run your code simply goto `New`>>`Empty File`. Copy paste the code as given in the question above. Then remember to save your file in `.cpp` format. It SHOULD work. If THIS fails. Seek more help and trying reinstalling CodeBlocks as administrator. Hope this helps! – Ic3fr0g Jun 01 '16 at 07:18
  • Thanks for your time but I've still got nothing. Yeah I guess I'll re install and try tinkering with the settings at some point. You know we don't have these sorts of problems when dealing with Arduino XD *that was a face, to my knowledge there is no versioon of of Arduino known as Arduino XD. lol – Casey McDermond Jun 01 '16 at 07:25
  • LOL! Casey I'm not quite sure why this is happening. Maybe go through a [tutorial](http://www.cplusplus.com/doc/tutorial/introduction/codeblocks/) on [CodeBlocks](http://www.cprogramming.com/code_blocks/). Hope this helps you out! – Ic3fr0g Jun 01 '16 at 07:34
0

Code::Blocks compiles using some built-in .dlls and i have sometimes found it needed the dll in the folder with the compliled .exe

if not that, try the console application template

i use TDM-GCC it compiles fine.

abe72
  • 1
  • 1