PDA

View Full Version : Compiling code from visual studio in xcode c++




ninjonxb
Nov 17, 2009, 02:58 PM
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).

#include <iostream>
#include <string>
using namespace std;

int main () {

string pswd;
string const PASSWORD = "CPLUS";
int numtries = 0, test;

do {
cout << "please enter password:";
getline(cin, pswd);
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?



lee1210
Nov 17, 2009, 04:02 PM
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

kainjow
Nov 17, 2009, 04:06 PM
http://lists.apple.com/archives/cocoa-dev/2009/Sep/msg01199.html

Try adding this to the top of your code (before the #includes):
#define _GLIBCXX_FULLY_DYNAMIC_STRING

ninjonxb
Nov 17, 2009, 04:14 PM
i am still getting used to th einterface and i think a pic will b easier
i was gona try to direcrtly post it but it isnt working for some reason
http://gallery.me.com/ninjonxb#100049/debug%20confusion&bgcolor=black

ninjonxb
Nov 17, 2009, 04:16 PM
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) ?

lloyddean
Nov 17, 2009, 05:29 PM
Works for me once the following error is corrected!


if (numtries = 3) {


Should be:


if (numtries == 3) {