Compiling code from visual studio in xcode c++

Discussion in 'Mac Programming' started by ninjonxb, Nov 17, 2009.

  1. ninjonxb macrumors newbie

    Joined:
    Nov 17, 2009
    #1
    I have some c++ code that is fairly basic. This code works perfectly in visual studio on windows but when i try the code in c++ i get runtime errors (i am asuming, I cant understand what it is telling me).
    PHP:
    #include <iostream>    
    #include <string>
    using namespace std;    

    int main () {
        
        
    string pswd;
        
    string const PASSWORD "CPLUS";
        
    int numtries 0test;
        
        do {
            
    cout << "please enter password:";
            
    getline(cinpswd);
            
    test PASSWORD.compare(pswd);
            if (
    test == 0)
            {
                
    cout << "you are correct." << endl;
                break;
            }
            else {
                
    cout << "please try again";
                
    numtries ++;
            }

        } while (
    numtries 3);
            if (
    numtries 3) {
                
    cout << "sorry, to many wrong password attempts";
            }
        
        return 
    0;
    }
    I wanted to use a simplier program that uses a good variety of things to see if it works. And it seems like i start running into problems when I am using getline and strings.

    Is there something special I have to do, to run standard C++ code?
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    Copy and paste your output. You said you don't understand it, so it seems best that you give us a chance to help.

    -Lee
     
  3. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #3
  4. ninjonxb thread starter macrumors newbie

    Joined:
    Nov 17, 2009
    #4
  5. ninjonxb thread starter macrumors newbie

    Joined:
    Nov 17, 2009
    #5
    ok, well that worked. Am I just asking for more headaches by trying to do this on xcode than just running windows virtualy or booting into it (as i do now) ?
     
  6. lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #6
    Works for me once the following error is corrected!

    Code:
            if (numtries = 3) { 
    
    Should be:

    Code:
            if (numtries == 3) { 
    
     

Share This Page