Like Tree2Likes
  • 2 Post By ZuK

error with xcode on win7

This is a discussion on error with xcode on win7 within the C++ Programming forums, part of the General Programming Boards category; This very simple c++ code ran correctly on my mac with xcode. int a got printed as 0. I ran ...

  1. #1
    Registered User
    Join Date
    Aug 2012
    Location
    colorado
    Posts
    2

    Question error with xcode on win7

    This very simple c++ code ran correctly on my mac with xcode. int a got printed as 0. I ran the same code on a win 7 machine with recently installed code::blocks and a was printed as 54. As a matter of fact when I gave other values to int a then the int a was still printed as 54 ???????

    Code:
    #include <iostream>
    using namespace std;
    int main( )
    {
    cout << "This is my first try" << endl;
    int a,b;
    a=0;
    b=3;
    cout << "a is  " << a << endl;
    
    return 0;
    
    }

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Your code as posted is fine, so your error must be elsewhere. Are you sure you're running the right program? Try deleting it and recompiling.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    Registered User
    Join Date
    Aug 2012
    Location
    colorado
    Posts
    2
    sorry for the trouble. the statement on the win system was a-0; and not a=0; I assume a-0; is valid but it sure is meaningless. Bad eyes and small printing cause lots of programming problems! Lou

  4. #4
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by louxx View Post
    sorry for the trouble. the statement on the win system was a-0; and not a=0; I assume a-0; is valid but it sure is meaningless. Bad eyes and small printing cause lots of programming problems! Lou

    Always turn on all warnings of the compiler

    Code:
    #include <iostream>
    using namespace std;
    int main( ) {
        cout << "This is my first try" << endl;
        int a,b;
        a-0; // <<== your typo
        b=3;
        cout << "a is  " << a << endl;
        return 0;
    }
    
    
    My compiler output
    [liveuser@localhost CTests]$ g++ tst.cc -Wall
    tst.cc: In function ‘int main()’:
    tst.cc:7:4: warning: statement has no effect [-Wunused-value]
    tst.cc:6:7: warning: variable ‘b’ set but not used [-Wunused-but-set-variable]
    tst.cc:9:21: warning: ‘a’ is used uninitialized in this function [-Wuninitialized]
    Kurt
    rags_to_riches and Elkvis like this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. exc_bad_access error when compiling c code in xcode
    By new_cuser in forum C Programming
    Replies: 6
    Last Post: 07-27-2011, 03:43 PM
  2. Unknown error Xcode
    By Insectoid in forum C Programming
    Replies: 2
    Last Post: 07-15-2011, 05:05 PM
  3. Linking error in Xcode.
    By bhdavis1978 in forum C Programming
    Replies: 2
    Last Post: 03-19-2010, 02:32 PM
  4. Error Loading Bitmaps in Xcode
    By hamishmcgee in forum C++ Programming
    Replies: 0
    Last Post: 12-01-2009, 02:11 PM
  5. Win7 console size
    By Mario F. in forum Tech Board
    Replies: 12
    Last Post: 08-05-2009, 01:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21