本文整理汇总了C++中AddressBook::vectorSize方法的典型用法代码示例。如果您正苦于以下问题:C++ AddressBook::vectorSize方法的具体用法?C++ AddressBook::vectorSize怎么用?C++ AddressBook::vectorSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AddressBook
的用法示例。
在下文中一共展示了AddressBook::vectorSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DETAILED
//.........这里部分代码省略.........
//x is left "
//y is right "
//token will count token # 1-11 for each field.
int x=0, y=0, token=0;
while(token<11)//The algorithm should keep looking for tokens until counter hits 11 tokens
{
//x starts looking for the first " from y (0 initially at the start of the string/loop)
x=currentline.find_first_of("\"", y);
//y will start looking for the next " starting from x+1
y=currentline.find_first_of("\"",x+1);
//This if check is not really needed but to be save, x" will always be less than y"
if(x<y)
{
token++;
}
substring=currentline.substr(x+1,(y-x)-1);
//substring is the token which will always be found at x+1 to y-1
//to get the length, starting from x+1, it is (y-x)-1...(there are also other ways to calculate)
bookOne.buildData(i,substring,token);
//After token is extracted to substring, it is pushed to the address book with it's respective
//token index counter "token"
//This was the tricky part...took me a while to figure it out =P
//y needs to get +1 to prevent x from finding y's " in the next loop. DUHHH!!
//Also this can be done with a third variable to look for commas but this is more efficient/easier.
y++;
}
}//for loop ends here bringing the extraction process to an end.
//This loop will validate the newly built vector of contacts. (Start at 1 as 0 is the title line)
for(int i=1; i<bookOne.vectorSize()-1; i++) //vectorsize returns the size the vector Contact data.
{
if(bookOne.contactValidate(i)==0)//this boolean function validates and DELETES invalid contacts.
{
bookOne.contactValidate(i);//calling the actual function DELETES invalid contacts (more detail in header file)
i=1; //Thus bringing i back to 1 is needed to check for all invalid contacts in the new vector size.
}
}
/////////////////////
//MAIN OPTION BLOCK//
/////////////////////
string option;
//option is the variable for the menu option input from the user
do{ //this do loop will run wile the option is not Q or q for quit.
do{ //this do loop will run until a valid option is received from the user.
displayMenu();
cout << "Select an option:";
cin >> option;
//if the option is longer than 1 character. (can probably leave out >1 as function checks for length also)
if(checkOption(option)==false || option.length()>1)
{
cout << "Invalid choice please try again.." << endl; //output invalid choice statement.
}
}while(checkOption(option)==false);
//Program will get here only if option is valid.
//Options are listed in order shown on project 3 description
//////////////////////////////
//OPTION [A] - Add a contact//