Thread: Code blocks help, too many errors!

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    4

    Code blocks help, too many errors!

    Hello again,

    Im having trouble compiling this code. I took this code from C++ for dummies, but it doesn't seem to work, why?

    Code:
    #include <stdio.h>
    #include<stdlib.h>
    #include<io.h>
    
    using namespace std;
    
    int main (int nNumberofArgs, char* pszArgs[])
    {
        int start;
        int n;
        long L;
        long long LL;
        float f;
        double d;
        long double Ld;
        int end;
    
        cout.setf(ios: :hex);
        cout.unsetf(ios: :dec);
    
        cout << "--- = " << &start << endl;
        cout << "&n = " << &n << endl;
        cout << "&L = " << &L << endl;
        cout << "&LL = " << &LL << endl;
        cout << "&f = " << &f << endl;
        cout << "&d = " << &d << endl;
        cout << "&Ld = " << &Ld << endl;
        cout << "--- = " << &end << endl;
    
        system("PAUSE");
        return 0;
    }
    please if anyone can help. Im using code blocks 10. I fixed a few bugs in the include statements, they said cstdio instead of stdio, things like that. I created this as an empty file no project, could that be the reason. I dunno the code loooks fine to me. Let me know!

    Thank-you

    GYes777

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If by "fixed the include statements", you mean "broke the include statements", then sure.

    <cstdio> is correct, not <stdio.h>.
    <cstdlib> is correct, not <stdlib.h>
    <iostream> is correct, not <io.h>.

    You're not allowed to put spaces between consecutive :: characters.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by GYes777 View Post
    I took this code from C++ for dummies, but it doesn't seem to work, why?
    Probably because you made a few mistakes while typing it in.

    Most of us don't bother to compile code that other's post, so you need to post some of your compiler error messages.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    In the following code you have a space between the colons, there should be no spaces between them "::".
    Code:
        cout.setf(ios: :hex);
        cout.unsetf(ios: :dec);
    You will also need to include the iostream header.

    Jim

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    To be honest, if you took that code straight from a book you are probably alot better off scrapping the book altogether. That code is nonstandard and outdated in more ways than one.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  2. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Linux Programming
    Replies: 0
    Last Post: 10-14-2002, 01:30 PM
  3. RAM/Swap Memory Code Errors
    By ghe1 in forum Linux Programming
    Replies: 2
    Last Post: 04-01-2002, 07:37 AM
  4. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 12:51 PM