Author Topic: Can't Run/Build my Program  (Read 20781 times)

Offline bluejayke

  • Multiple posting newcomer
  • *
  • Posts: 18
Can't Run/Build my Program
« on: December 07, 2011, 01:21:29 am »
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!

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Can't Run/Build my Program
« Reply #1 on: December 07, 2011, 01:45:02 am »
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...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Radek

  • Multiple posting newcomer
  • *
  • Posts: 104
Re: Can't Run/Build my Program
« Reply #2 on: December 08, 2011, 06:15:40 pm »
(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).

Offline JackDawson

  • Multiple posting newcomer
  • *
  • Posts: 37
Re: Can't Run/Build my Program
« Reply #3 on: December 08, 2011, 06:57:40 pm »
@ 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

  • Guest
Re: Can't Run/Build my Program
« Reply #4 on: December 08, 2011, 07:24:13 pm »
@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++.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Can't Run/Build my Program
« Reply #5 on: December 08, 2011, 09:13:39 pm »
You all (except oBFusCATed) should read the forum rules !

This is not a general programming board/website, neither it is a compiler-error board.
Such questions should not be asked here, and they should not be answered, the cause is simple:

In case you wonder why we are so strict: I could say: "Search the forum" - as this has been discussed a lot. To make is short: By law we (the devs/moderators) are responsible for the content of our forum. This means we need to read all posts. If you want us to continue the development of C::B and have the time to answer some of the questions that are really related to C::B, apply the rules above. It's obviously a matter of time for us.

Please respect this and respect the cause for this.

If this has to be repeated over and over, because nobody seems to be able to read these simple rules or nobody wants to accept these rules, it can happen, that the admins, mods, devs and sometimes normal users sound harsh or unfriendly in there answers.

And this post is one of the real annoying and time-consuming posts, that are absolutely unneeded.
And I have to spend time for this post, time I could better use for my family or workig on C::B issues/improvements, that means this time is lost for all other users or mor worse for my family and me.

And this questions from users who try to compile c++-files with c-endinngs and therefore with a c-compiler have been asked tons of time in this forum, and in the web, so such an answer, like the one from oBFusCATed is fully understandable for me.

zabzonk

  • Guest
Re: Can't Run/Build my Program
« Reply #6 on: December 08, 2011, 09:32:23 pm »
@jens

If the question had been about the specifics of iostreams or whatever, then I would entirely agree with you.  However, it is actually about the naming of files and about how CB (via the configured compiler) treats those files, which to me seems entirely on-topic. I agree it is a FAQ.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Can't Run/Build my Program
« Reply #7 on: December 08, 2011, 09:40:40 pm »
@jens

If the question had been about the specifics of iostreams or whatever, then I would entirely agree with you.  However, it is actually about the naming of files and about how CB (via the configured compiler) treats those files, which to me seems entirely on-topic. I agree it is a FAQ.

It's more or less on-topic, but has been answered many times here and in the web. And I would agree if a user comes and asks why C::B treats a file as c-file, ebven if it is meant as c++-file, but not if it looks like a user don't know the difference beteen c and c++.

This is an absolutely basic programming thing and it does not belong into this forum.