Visual Studio program to xcode

I recently started learning c++ in school in the visual studio environment. I am not going to be working on a program on the side at home where I have a mac so I want to start using xcode. I was able to locate a c++ program on someones blog that gives me a good template to start modifying. I first tested the program as in visual studio and as expected it runs just fine. I have no started trying to get it to run in xcode but it is giving me some throwback errors. Specifically I get the following error:

1
2
libc++abi.dylib: terminating with uncaught exception of type std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >
(lldb) 


and it directs me to line 91 of the .cpp file here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "User.h"
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>

using namespace std;

User::User(){

}

string User::getFn() const{ 
	//POST: return first name
	return fn;
}
string User::getLn() const{ 
	//POST: return last name
	return ln;
}
string User::getID() const{ 
	//POST: return ID
	return id;
}
string User::getUserid() const{ 
	//POST: return userid
	return userid;
}
string User::getPassword() const{ 
	//POST: return password
	return password;
}

void User::setFn(string input){
	//PRE: takes  input of firstname
	//POST: sets the first name after checking errors
	string errorMsg;
	for (int k = 0; k < input.length(); k++)
		if (input[k]==' ') 
		{	errorMsg = "Name cannot contain a blank.";
			throw errorMsg;
		}

	for (int k = 0; k < input.length(); k++)
		if (input[k]>='0' && input[k]<='9') 
		{	errorMsg = "Name cannot contain a digit.";
			throw errorMsg;
		}
	fn = input;
}

void User::setLn(string input){
	//PRE: takes  input of lastname
	//POST: sets the last name after checking errors
	string errorMsg;
	for (int k = 0; k < input.length(); k++)
		if (input[k]==' ') 
		{	errorMsg = "Name cannot contain a blank.";
			throw errorMsg;
		}

	for (int k = 0; k < input.length(); k++)
		if (input[k]>='0' && input[k]<='9') 
		{	errorMsg = "Name cannot contain a digit.";
			throw errorMsg;
		}

	ln = input;
}

void User::setID(string ID){
	//PRE: takes input of ID number
	//POST: sets the id number 
	id = ID;
}

void User::setUserid(string ln, string id){
	//PRE: takes last name and Id
	//POST: returns the first 6letters of last name and last 2 of id number
	userid = ln.substr(0, 6) + id.substr(id.size() - 2);
		
}


void User::setPassword(string input){
	//PRE: takes input of password
	//POST: sets the password for that users after error checking
	string errorMsg;
	if((input.length() < 6  || input.length() > 10 )){
		errorMsg = "Password must be between 6 and 10 charaters";
		throw errorMsg;
	}

	for (int k = 0; k < input.length(); k++){
		if (std::string::npos == input.find_first_of("0123456789")) 
		{
			errorMsg = "Password must contain a digit";
			throw errorMsg;
		}else if (std::string::npos == input.find_first_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ")) 
		{
			errorMsg = "\nPassword must contain a Uppercase letter";
			throw errorMsg;
		}

	}

	password = input;
	
			
}

void User::changePassword(string oldpass, string newpass){
	//PRE: takes in old password and the new password
	//POST: sets the New password for user
	User u;
	if(u.password == oldpass){
		cout << "\nPlease enter new password";
		cin >> newpass;
		u.setPassword(newpass);
	}

}



At first glance it appears to me that the program doesn't like the password listed in the .txt file, like it is too short or too long. I've dismissed that though because it is exactly the same text file I was using on Windows. My next guess is maybe there are some libraries that xcode doesn't include by default but Visual studio does. If that is the case I don't know which ones or how to even find that out.

The website with all of the c++ code is located here:

http://www.nkonecny.com/blog/2011/09/30/creating-a-user-login/

All of the code doesn't appear in the boxes on the web page. You have to download the zip file located at the bottom of the page.
I've been trying to do some debugging of my own and it seems like the problem might actually be related to the password file. I added a cout for the password length like this around the global lines of 89 - 94:

1
2
3
4
5
6
	if((input.length() < 6  || input.length() > 10 )){
		cout << input.length() << endl;
        getchar();
        errorMsg = "Password must be between 6 and 10 charaters";
		throw errorMsg;
	}


And it spits back that the length is 0. Odd, so I am wondering now if somehow xcode isn't opening the file properly? I have the text file containing the passwords in the same directory as the .cpp and .h files.
The only place I see setPassword being called is on line 119 inside of changePassword. However, the argument you pass here is one that you're getting from standard input (generally, the user at the keyboard) on line 118. An external file doesn't have anything to do with it.
Right. So when the program starts up there is a text file of some generic user names, user ids, and passwords that are supposed to be read. Then a console window will appear where there is a prompt to enter the user id. Once that is input then the password must be input. Then a screen comes up where the user can change first name, last name, password, or quit. The problem is this code does just that when run in Visual Studio but when run in xcode it breaks and I cannot even get the login prompt. Hopefully that clarifies.
Can you set a breakpoint before that exception and look at the call stack when it is hit?
Last edited on
I'm not entirely sure which information you want. But I'm hoping this is it:

1
2
3
4
5
libdyld.dylib`start:
0x7fff9250e5fc:  nop    
0x7fff9250e5fd:  movl   %eax, %edi
0x7fff9250e5ff:  callq  0x7fff9250e630            ; symbol stub for: exit
0x7fff9250e604:  hlt  


I also took a screen shot of some information I cannot copy and paste of the stack that shows some different information.

https://dl.dropboxusercontent.com/u/14334980/Screen%20Shot%202013-12-18%20at%2016.32.02%20PM.png
Topic archived. No new replies allowed.