Last active
October 16, 2018 06:02
-
-
Save tejashah88/0a038702eff1fcd3799c46dc567a757b to your computer and use it in GitHub Desktop.
List of common functions used in COMSC-165.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int readInt(); | |
char readChar(); | |
float readFloat(); | |
string readWord(); | |
string readLine(); | |
void swapInt(int &a, int &b); | |
void swapChar(char &a, char &b); | |
void swapFloat(float &a, float &b); | |
void swapString(string &a, string &b); | |
int readInt() { | |
int input; | |
cin >> input; | |
while (cin.fail()) { | |
cin.clear(); | |
cin.ignore(); | |
cin >> input; | |
} | |
cin.ignore(); | |
return input; | |
} | |
char readChar() { | |
char input; | |
cin >> input; | |
while (cin.fail()) { | |
cin.clear(); | |
cin.ignore(); | |
cin >> input; | |
} | |
cin.ignore(); | |
return input; | |
} | |
float readFloat() { | |
float input; | |
cin >> input; | |
while (cin.fail()) { | |
cin.clear(); | |
cin.ignore(); | |
cin >> input; | |
} | |
cin.ignore(); | |
return input; | |
} | |
string readWord() { | |
string input; | |
cin >> input; | |
while (cin.fail()) { | |
cin.clear(); | |
cin.ignore(); | |
cin >> input; | |
} | |
cin.ignore(); | |
return input; | |
} | |
string readLine() { | |
string input; | |
getline(cin, input); | |
return input; | |
} | |
void swapInt(int &a, int &b) { | |
int temp = a; | |
a = b; | |
b = temp; | |
} | |
void swapChar(char &a, char &b) { | |
char temp = a; | |
a = b; | |
b = temp; | |
} | |
void swapFloat(float &a, float &b) { | |
float temp = a; | |
a = b; | |
b = temp; | |
} | |
void swapString(string &a, string &b) { | |
string temp = a; | |
a = b; | |
b = temp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment