Trouble Compiling 1st program

Oct 13, 2012 at 8:23pm
I'm trying to follow this site's guide for C++ at http://cplusplus.com/doc/tutorial/program_structure/. Very basic to begin with, or so I thought. I've downloaded Code::Blocks MinGW, newest version. I've also searched the forums and based on that advice I changed the compiler path under Settings -> Compiler and debugger (using auto detect to make sure it is correct). Now, when I try to run the following I am told I need to build first:

// my first program in C++

#include <iostream>
using namespace std;

int main ()
{
cout << "Hello World!";
return 0;
}

However, when asked 'Do you want to build it now?' and clicking Yes, nothing happens and the box reappears. If I select No, then a command window appears which states 'Process returned 0 (0x0) execution time 0.001 s Press any key to continue.'

The build log reports the following:
Checking for existence: D:\Project 1\bin\Debug\Project 1.exe
Executing: "C:\Program Files (x86)\CodeBlocks/cb_console_runner.exe" "D:\Project 1\bin\Debug\Project 1.exe" (in D:\Project 1\.)
Process terminated with status 0 (1 minutes, 10 seconds)

Can someone help and give insight?
Last edited on Oct 13, 2012 at 8:29pm
Oct 13, 2012 at 8:32pm
Try .h after headers.
As in #include <iostream.h>
Oct 13, 2012 at 8:45pm
Tried, and there was no change.
Oct 13, 2012 at 9:10pm
I just tried it with Borland C++ Builder v6 with the .h and it worked fine.
Check your compiler installation.
Oct 13, 2012 at 9:17pm
There's nothing wrong with this source code:

// my first program in C++

#include <iostream.h>
using namespace std;

int main ()
{
cout << "Hello World!";
return 0;
}

Last edited on Oct 13, 2012 at 9:17pm
Oct 13, 2012 at 9:19pm
My guess is that it built successfully and then ran and closed so quickly that you missed it.

See here: http://www.cplusplus.com/forum/beginner/1988/
Oct 13, 2012 at 9:21pm
Good point! Open the command prompt window and run it from DOS if the .exe exists.
Last edited on Oct 13, 2012 at 9:21pm
Oct 13, 2012 at 9:44pm
Okay, I attempted to add the code from threat 1988 and my program did not have any change. The command window still opened with the exact same text, and there was no 'Hello World!'. The code (with pause) is now:

// my first program in C++

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

int main ()
{
cout << "Hello World!";
return 0;

std::cout << "Press ENTER to continue...";
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
}

I also tried limits.h, and that produced no different results.

After trying 'debug' (not sure this is helpful, since sunrise38501 already tested and made sure there's no bug in the code), the Build Log now shows:
-------------- Build: Debug in Project 1 ---------------

Linking stage skipped (build target has no object files to link)
Nothing to be done.

Not sure if that's helpful. I'm really shooting in the dark, as before I have only programmed in QBasic and Pascal.
Oct 13, 2012 at 9:59pm
I have a suggestion ...
1
2
3
4
5
6
7
8
9
10
11
12
13
// my first program in C++
#include <iostream.h>
#include <limits>
    using namespace std;

int main ()
{
    cout << "Hello World!";
    return 0;                         //   <--- PROGRAM ENDS HERE

    std::cout << "Press ENTER to continue...";  // this code never executed
    std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
}


Try to re-edit this and put the return 0; line after the two new lines, so it is just before the closing brace.
Last edited on Oct 13, 2012 at 10:11pm
Oct 13, 2012 at 10:08pm
The second report of the Build Log only shows what I saw after running debug. When I run the program (although it never seems to let me build), I still receive something that ends 'process terminated with status 0'.

In D:\Project 1 I do not have \bin, only \Program 1.cpp and \Program 1.cbp.

There may be something more fundamentally wrong with how CB is being used, although it isn't the compiler path.
Oct 14, 2012 at 2:06am
u didnt install it correctly cause its not linking correctly. try code::blocks.
Oct 14, 2012 at 2:09am
Never use iostream.h, it is old and deprecated.
Oct 14, 2012 at 10:03am
Okay, thank you everyone - it's finally working.

I took your advice, Aramil of Elixia, and uninstalled everything and reinstalled it. Then, I downloaded MinGW by itself (instead of the CB package with both) and linked the compiler in CB to the new location. Then, I tried building and I came back telling me iostream.h didn't exist, so I removed the .h and everything worked!
Topic archived. No new replies allowed.