abandon sstream a cause error mtn atoi
This commit is contained in:
10
.gitignore
vendored
10
.gitignore
vendored
@@ -1,8 +1,3 @@
|
||||
# These are some examples of commonly ignored file patterns.
|
||||
# You should customize this list as applicable to your project.
|
||||
# Learn more about .gitignore:
|
||||
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore
|
||||
|
||||
# Node artifact files
|
||||
node_modules/
|
||||
dist/
|
||||
@@ -48,3 +43,8 @@ Thumbs.db
|
||||
*.mov
|
||||
*.wmv
|
||||
|
||||
# personnals
|
||||
.o
|
||||
builds/
|
||||
.swp
|
||||
.out
|
||||
|
||||
BIN
d00/ex00/megaphone
Executable file
BIN
d00/ex00/megaphone
Executable file
Binary file not shown.
@@ -3,7 +3,7 @@
|
||||
|
||||
PhoneBook::PhoneBook( void ) {
|
||||
|
||||
this->contact_count = 0;
|
||||
this->_contact_count = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -16,50 +16,50 @@ void PhoneBook::add_contact() {
|
||||
std::string str;
|
||||
int it;
|
||||
|
||||
this->contact_count++;
|
||||
it = this->contact_count;
|
||||
this->_contact_count++;
|
||||
it = this->_contact_count;
|
||||
if (it > 8)
|
||||
it = 1;
|
||||
it--;
|
||||
|
||||
std::cout << B_CYAN "enter a first name pliz :" << std::endl;
|
||||
while (contact[it].get_first().length() == 0)
|
||||
while (_contact[it].get_first().length() == 0)
|
||||
{
|
||||
std::cout << B_BLUE "-> " RESET;
|
||||
std::getline(std::cin, str);
|
||||
this->contact[it].add_first(str);
|
||||
this->_contact[it].add_first(str);
|
||||
}
|
||||
|
||||
std::cout << B_CYAN "enter a last name pliz :" << std::endl;
|
||||
while (contact[it].get_last().length() == 0)
|
||||
while (_contact[it].get_last().length() == 0)
|
||||
{
|
||||
std::cout << B_BLUE "-> " RESET;
|
||||
std::getline(std::cin, str);
|
||||
this->contact[it].add_last(str);
|
||||
this->_contact[it].add_last(str);
|
||||
}
|
||||
|
||||
std::cout << B_CYAN "enter a nickname pliz :" << std::endl;
|
||||
while (contact[it].get_nick().length() == 0)
|
||||
while (_contact[it].get_nick().length() == 0)
|
||||
{
|
||||
std::cout << B_BLUE "-> " RESET;
|
||||
std::getline(std::cin, str);
|
||||
this->contact[it].add_nick(str);
|
||||
this->_contact[it].add_nick(str);
|
||||
}
|
||||
|
||||
std::cout << B_CYAN "enter a number pliz :" << std::endl;
|
||||
while (contact[it].get_num().length() == 0)
|
||||
while (_contact[it].get_num().length() == 0)
|
||||
{
|
||||
std::cout << B_BLUE "-> " RESET;
|
||||
std::getline(std::cin, str);
|
||||
this->contact[it].add_num(str);
|
||||
this->_contact[it].add_num(str);
|
||||
}
|
||||
|
||||
std::cout << B_CYAN "enter a secret of this contact pliz :" << std::endl;
|
||||
while (contact[it].get_secret().length() == 0)
|
||||
while (_contact[it].get_secret().length() == 0)
|
||||
{
|
||||
std::cout << B_BLUE "-> " RESET;
|
||||
std::getline(std::cin, str);
|
||||
this->contact[it].add_secret(str);
|
||||
this->_contact[it].add_secret(str);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,12 +71,12 @@ std::string truncate(std::string str, size_t len) {
|
||||
|
||||
}
|
||||
|
||||
void PhoneBook::print_phonebook() {
|
||||
int PhoneBook::print_phonebook() {
|
||||
|
||||
std::cout << std::endl;
|
||||
int it;
|
||||
|
||||
it = this->contact_count;
|
||||
it = this->_contact_count;
|
||||
if (it > 8)
|
||||
it = 8;
|
||||
it--;
|
||||
@@ -91,42 +91,44 @@ void PhoneBook::print_phonebook() {
|
||||
for (int i = 0; i <= it; i++)
|
||||
{
|
||||
std::cout << "|" << std::setw(10) << i;
|
||||
std::cout << "|" << std::setw(10) << truncate(contact[i].get_first(), 10);
|
||||
std::cout << "|" << std::setw(10) << truncate(contact[i].get_last(), 10);
|
||||
std::cout << "|" << std::setw(10) << truncate(contact[i].get_nick(), 10);
|
||||
std::cout << "|" << std::setw(10) << truncate(_contact[i].get_first(), 10);
|
||||
std::cout << "|" << std::setw(10) << truncate(_contact[i].get_last(), 10);
|
||||
std::cout << "|" << std::setw(10) << truncate(_contact[i].get_nick(), 10);
|
||||
std::cout << "|" << std::endl;
|
||||
}
|
||||
if (this->_contact_count == 0)
|
||||
std::cout << "| EMPTY |" << std::endl;
|
||||
std::cout << " ------------------------------------------- " << std::endl;
|
||||
std::cout << std::endl;
|
||||
return this->_contact_count;
|
||||
}
|
||||
|
||||
void PhoneBook::print_contact( int id ) {
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << B_CYAN "FIRST NAME : " << RESET << this->contact[id].get_first() << std::endl;
|
||||
std::cout << B_CYAN " LAST NAME : " << RESET << this->contact[id].get_last() << std::endl;
|
||||
std::cout << B_CYAN " NICKNAME : " << RESET << this->contact[id].get_nick() << std::endl;
|
||||
std::cout << B_CYAN " NUMBER : " << RESET << this->contact[id].get_num() << std::endl;
|
||||
std::cout << B_CYAN " SECRET : " << RESET << this->contact[id].get_secret() << std::endl;
|
||||
std::cout << B_PURPLE "FIRST NAME : " << RESET << this->_contact[id].get_first() << std::endl;
|
||||
std::cout << B_PURPLE " LAST NAME : " << RESET << this->_contact[id].get_last() << std::endl;
|
||||
std::cout << B_PURPLE " NICKNAME : " << RESET << this->_contact[id].get_nick() << std::endl;
|
||||
std::cout << B_PURPLE " NUMBER : " << RESET << this->_contact[id].get_num() << std::endl;
|
||||
std::cout << B_PURPLE " SECRET : " << RESET << this->_contact[id].get_secret() << std::endl;
|
||||
|
||||
}
|
||||
|
||||
void PhoneBook::search_contact() {
|
||||
|
||||
std::string str;
|
||||
std::stringstream convert;
|
||||
std::string index;
|
||||
int id;
|
||||
|
||||
this->print_phonebook();
|
||||
if (this->print_phonebook() == 0)
|
||||
return;
|
||||
id = -1;
|
||||
std::cout << std::endl << B_CYAN "choose an index :" << std::endl;
|
||||
while (id < 0 || id > this->contact_count - 1 || id > 7)
|
||||
while (id < 0 || id > this->_contact_count - 1 || id > 7)
|
||||
{
|
||||
std::cout << B_BLUE "-> " RESET;
|
||||
std::getline(std::cin, str);
|
||||
convert << str;
|
||||
convert >> id;
|
||||
if (id < 0 || id > this->contact_count - 1 || id > 7)
|
||||
std::getline(std::cin, index);
|
||||
id = std::atoi(index.c_str());
|
||||
if (id < 0 || id > this->_contact_count - 1 || id > 7)
|
||||
std::cout << B_RED "sorry, not a valid index" RESET << std::endl;
|
||||
}
|
||||
this->print_contact(id);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <cstdlib>
|
||||
|
||||
class PhoneBook {
|
||||
|
||||
@@ -15,24 +15,16 @@ class PhoneBook {
|
||||
PhoneBook();
|
||||
~PhoneBook();
|
||||
|
||||
void add_contact();
|
||||
void search_contact();
|
||||
void print_phonebook();
|
||||
void print_contact( int id);
|
||||
void add_contact();
|
||||
void search_contact();
|
||||
int print_phonebook();
|
||||
void print_contact( int id);
|
||||
|
||||
private:
|
||||
|
||||
Contact contact[8];
|
||||
int contact_count;
|
||||
Contact _contact[8];
|
||||
int _contact_count;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* class PhoneBook :
|
||||
* add_contact
|
||||
* print_phonebook
|
||||
* search_by_index
|
||||
* exit
|
||||
*/
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -26,12 +26,3 @@ int main() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// B_GRAY "\e[1;30m"
|
||||
// B_RED "\e[1;31m"
|
||||
// B_GREEN "\e[1;32m"
|
||||
// B_YELLOW "\e[1;33m"
|
||||
// B_BLUE "\e[1;34m"
|
||||
// B_PURPLE "\e[1;35m"
|
||||
// B_CYAN "\e[1;36m"
|
||||
// B_WHITE "\e[1;37m"
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user