Author Topic: Basic program won't work!  (Read 5037 times)

Offline Mr.Ninja

  • Single posting newcomer
  • *
  • Posts: 2
Basic program won't work!
« on: January 02, 2012, 03:53:37 am »
Hello,

I am just learning C++ and am getting info off of www.cprogramming.com. I have a basic program which won't run properly. First I hit new, and then select console application. I make sure it is C++ and then name it and do the default setting. I tthen create my program;

include <iostream>

using namespace std;

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


I hit the debugger and it gives me this;




Building to ensure sources are up-to-date
Build succeeded
Selecting target:
Debug
Adding source dir: C:\Users\David\Desktop\Personal\Poof\Library\
Adding source dir: C:\Users\David\Desktop\Personal\Poof\Library\
Adding file: bin\Debug\Library.exe
Starting debugger:
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
Debugger name and version: GNU gdb 6.8
Continuing...
The program is not being run.
Debugger finished with status 0

It does not allow me to start it as it says it is not built yet, but when I build it;


-------------- Build: Debug in Library ---------------

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

I do not know what to do.

Offline Radek

  • Multiple posting newcomer
  • *
  • Posts: 104
Re: Basic program won't work!
« Reply #1 on: January 02, 2012, 11:13:50 am »
(1) First of all, your int main() needs to return something. Add return 0. This is an error but you seem not to get any error messages. A possible reason is a "default code" added by project wizard to your project automatically. Therefore
(2) Check your project and remove all files which are not yours from it.
(3) Try again.

zabzonk

  • Guest
Re: Basic program won't work!
« Reply #2 on: January 02, 2012, 02:40:24 pm »
Quote
First of all, your int main() needs to return something. Add return 0. This is an error

It's not an error in C++ - main does not require an explicit return.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7592
    • My Best Post
Re: Basic program won't work!
« Reply #3 on: January 02, 2012, 06:01:56 pm »
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F

Turn on Full Compiler logging and then do a full rebuild. The compiler log should show what it did; read/post it and the cause should be able to be found.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline maxum

  • Single posting newcomer
  • *
  • Posts: 2
Re: Basic program won't work!
« Reply #4 on: January 02, 2012, 07:09:44 pm »
Preprocessor commands needs # before them.
Ex.:
#include <iostream>

Offline Mr.Ninja

  • Single posting newcomer
  • *
  • Posts: 2
Re: Basic program won't work!
« Reply #5 on: January 03, 2012, 03:37:41 am »
Thank you stahta01 I have done that and this is where it says it stops working when I run it:

123 (red bar) operator(_ios_type& (*_pf)(_ios_type&))

On the build message:


c:\program file... 123 error: expected type-specifier before '(' token|
c:\program file... 123 error: expected ';' before '(' token|
c:\program file... 129 error: expected ';' before '__istream_type'|
||=== Build finished: 3 errors, 0 warnings ===|

thanks for the help.

And maxum, not trying to be rude, but when I was copying and pasting I missed the # sign.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7592
    • My Best Post
Re: Basic program won't work!
« Reply #6 on: January 03, 2012, 04:03:30 am »
1. Copy your program source code somewhere outside of the "program files" folder.
It is NOT considered safe or easy to compile files in the "program files" folder.
2. Fix the compiler errors.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org