User forums > Help

Can't Run/Build my Program

(1/2) > >>

bluejayke:
Here is my basic code:

#include <iostream>
 
using namespace std;
 
int main()
{
  cout<<"HEY, you, I'm alive! Oh, and Hello World!\n";
  cin.get();
}


I am saving it to the bin in the Mingw folder (where compiler is saved) but I am still getting the following errors:

C:\Program Files (x86)\CodeBlocks\MinGW\bin\Program1.c|1|error: iostream: No such file or directory|
C:\Program Files (x86)\CodeBlocks\MinGW\bin\Program1.c|3|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'namespace'|
C:\Program Files (x86)\CodeBlocks\MinGW\bin\Program1.c||In function 'main':|
C:\Program Files (x86)\CodeBlocks\MinGW\bin\Program1.c|7|error: 'cout' undeclared (first use in this function)|
C:\Program Files (x86)\CodeBlocks\MinGW\bin\Program1.c|7|error: (Each undeclared identifier is reported only once|
C:\Program Files (x86)\CodeBlocks\MinGW\bin\Program1.c|7|error: for each function it appears in.)|
C:\Program Files (x86)\CodeBlocks\MinGW\bin\Program1.c|8|error: 'cin' undeclared (first use in this function)|
||=== Build finished: 6 errors, 0 warnings ===|







someone help!

oBFusCATed:
Read this: http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F

If you do not find the answer there, please just quit programming...

Radek:
(1) You are using a C++ header (iostream) in a C program (program1.c). Moreover, you are using namespaces and other features not defined in C. This cannot pass.
(2) Where is your project folder? Looking at the error listing, you are clobbering the compiler folder with files which should not be there.
(3) The first error says that you do not have iostream on the INCLUDE path. If you have installed a C compiler (and not a C++ compiler), you do not have iostream at all.

What to do?

(1) Check whether you have installed a C++ compiler.
(2) Create a project folder!
(3) Rename program1.c to program1.cpp (the simplest way) or force the C++ compiler on a C file (less simple but possible).

JackDawson:
@ Obfuscated..  LMAO..  having a bad day are you ?  HAHAHAHA

@ BlueJayke - Hey there Blue, Radek is correct, you have to know the differences between a few things and saving the file to the BIN folder is never a good idea. HOWEVER, there are books and such that teach you step by step how to program C++ from the beginning. Here is one I recommend :

http://www.amazon.com/Beginning-C-Through-Game-Programming/dp/1435457420/ref=sr_1_1?s=books&ie=UTF8&qid=1323366173&sr=1-1

It teaches you how to program using the console to make a small game. That game alone will give you some basics and teach you things that are obvious to the rest of us. Another thing too, if you do not know C++, you really should not start out with Code::Blocks. Get that book, follow its instructions. It will tell you where to get a trial copy of Microsoft Visual C++ compiler. ( The trial will give you 90 days or more. ) From there you read and follow the chapters thoroughly. AFTER, and only AFTER you have finished the book, you should have enough understanding of what its all about and then come back to code::blocks and try it again. But this time, get Code::Blocks WITH the MinGW compiler. It is different from Visual Studio C++, but it will compile the SAME C++ code from that book if you set it up correctly.

Another hint, and this is why Obfuscated was like "please just quit programming", is because you really need to read EVERYTHING first. Do searches, and watch Youtube videos. There is a TON of info on youtube about C++. What you were trying to do is build the house without a foundation first. Meaning, you have to understand from the basics before you jump right into something as hefty as Code::Blocks which is not meant for the beginner.

Hope this info finds you well.

zabzonk:
@bluejayke

Rename your file so that it has a .cpp extension, and all will be well. If you give it a .c extension, it is compiled as if it were C code, not C++.

Navigation

[0] Message Index

[#] Next page

Go to full version