c++ give options string
C++
string StringOptionsBox(int count, ...)
{
bool bValidSelection = 1;
do
{
//set the border options
char sczCorners = '+';
char sczVerticalFillers = '|';
char sczHorizontalFillers = '-';
char sczGeneralFillers = ' ';
// set the spacing options
int iLineWidth = 50;
int iOptionSpace = 25;
int iNumberSpace = 3;
int iTabSpace = 3;
int iRightSpace = iLineWidth - iOptionSpace - iNumberSpace - iTabSpace - 1;
va_list arguments; // A place to store the list of arguments
va_start(arguments, count); // Initializing arguments to store all values after count
//////////////////////////////////////////////////////////////////////////////////////
// LAYOUT THE INTERFACE AND PROMPT THE USER'S SELECTION //
//////////////////////////////////////////////////////////////////////////////////////
//Top line of the output
cout << sczCorners << setw(iLineWidth) << setfill(sczHorizontalFillers) << ""
<< sczCorners << "\n";
//Main Lines of the output
for (int i = 1; i <= count; i++)
{
cout << sczVerticalFillers;
cout << setw(iNumberSpace) << setfill(sczGeneralFillers) << right << i << ".";
cout << setw(iTabSpace) << setfill(sczGeneralFillers) << left << "";
cout << setw(iOptionSpace) << setfill(sczGeneralFillers) << left << va_arg(arguments, char *);
cout << setw(iRightSpace) << setfill(sczGeneralFillers) << left << "" << sczVerticalFillers << "\n";
}
//Bottom line of the output
cout << sczCorners << setw(iLineWidth) << setfill(sczHorizontalFillers) << "" << sczCorners << "\n";
va_end(arguments); // Cleans up the list
// User's selection process
string sSelected;
cout << "\nSelect one of the above options: ";
std::getline(cin, sSelected);
//////////////////////////////////////////////////////////////////////////////////////
// RETRIEVE THE STRING THAT WAS SELECTED //
//////////////////////////////////////////////////////////////////////////////////////
va_list arguments2; // A place to store the list of arguments
va_start(arguments2, count); // Initializing arguments to store all values after count
//Main Lines of the output
for (int i = 1; i <= count; i++)
{
if (i == atoi(sSelected.c_str()))
{
return va_arg(arguments2, char *); // returns the string that was selected
}
else if (i != count)
{
va_arg(arguments2, char *);
}
else
{
va_arg(arguments2, char *);
}
}
va_end(arguments2);
//////////////////////////////////////////////////////////////////////////////////////
// MAKE PROVISIONS FOR IF THE SELECTION IS INCORRECT //
//////////////////////////////////////////////////////////////////////////////////////
cout << "\nERROR \nThe option that you have selected - " << sSelected << " - does not exist. Please try again. \n\n";
bValidSelection = 0;
} while (bValidSelection != 1);
}
Also in C++:
- Title
- initialize int c++
- Category
- C++
- Title
- traverse map c++
- Category
- C++
- Title
- repeating character in c++
- Category
- C++
- Title
- append string to another string c++
- Category
- C++
- Title
- iostream library in cpp
- Category
- C++
- Title
- c++ string to vector int
- Category
- C++
- Title
- vector pop back
- Category
- C++
- Title
- matrix class in c++
- Category
- C++
- Title
- filling 2d array with 0 c++
- Category
- C++
- Title
- floor() in c++
- Category
- C++
- Title
- memset
- Category
- C++
- Title
- count function c++
- Category
- C++
- Title
- stringstream in c++ with delimiter
- Category
- C++
- Title
- char vector to string c++
- Category
- C++
- Title
- how to ensure the user inouts a int and not anything else c++
- Category
- C++
- Title
- Find the duplicate in an array of N integers.
- Category
- C++
- Title
- rgb(100,100,100,0.5) validation c++
- Category
- C++
- Title
- COnvert string to char * C++
- Category
- C++
- Title
- checking an int in c++
- Category
- C++
- Title
- get data from terminal c++
- Category
- C++
- Title
- unsorted array to bst
- Category
- C++
- Title
- how to know the correct class of objects cpp
- Category
- C++
- Title
- cube mapping sdl
- Category
- C++
- Title
- friend function in c++
- Category
- C++
- Title
- map insert c++
- Category
- C++
- Title
- unordered_set in c++ and ordered set diff
- Category
- C++
- Title
- select elements from array C++
- Category
- C++
- Title
- how can make string value in cpp
- Category
- C++
- Title
- compile c++ linux
- Category
- C++
- Title
- c++ switch case statement
- Category
- C++
- Title
- creare array con c++
- Category
- C++
- Title
- c++ declare variable
- Category
- C++
- Title
- how to sort a vector in reverse c++
- Category
- C++
- Title
- call by reference c++ example
- Category
- C++
- Title
- residuo en lenguaje c
- Category
- C++
- Title
- how to have a queue as a parameter in c++
- Category
- C++
- Title
- is x prime?
- Category
- C++
- Title
- c++ pi
- Category
- C++
- Title
- intersection between vector c++
- Category
- C++
- Title
- error: invalid use of template-name without an argument list
- Category
- C++
- Title
- else if c++
- Category
- C++
- Title
- min heap priority queue c++
- Category
- C++
- Title
- range based for loop c++
- Category
- C++
- Title
- modular exponentiation c++
- Category
- C++
- Title
- c++ functions
- Category
- C++
- Title
- c++ program to find gcd of 3 numbers
- Category
- C++
- Title
- mysqli connect
- Category
- C++
- Title
- how to iterate through array in c++
- Category
- C++
- Title
- max in c++
- Category
- C++
- Title
- c++ ros subscriber
- Category
- C++
- Title
- map arduino
- Category
- C++
- Title
- c++ append to list
- Category
- C++
- Title
- zeros of array c++
- Category
- C++
- Title
- removing repeated characters in a string c++
- Category
- C++
- Title
- switch case sinax c++
- Category
- C++
- Title
- c++ movment
- Category
- C++
- Title
- c++ overloaded == operator
- Category
- C++
- Title
- how initilaize deffult value to c++ class
- Category
- C++
- Title
- private and public in namespace cpp
- Category
- C++
- Title
- how to initialize a vector in c++
- Category
- C++
- Title
- can we compare a long long int with int in c++ using max or min functions
- Category
- C++
- Title
- queue c++
- Category
- C++
- Title
- new c++
- Category
- C++
- Title
- convert string to stream c++
- Category
- C++
- Title
- input a string in c++
- Category
- C++
- Title
- min and max heap in cpp
- Category
- C++
- Title
- chess perft 5
- Category
- C++
- Title
- string to number in c++
- Category
- C++
- Title
- maximum subarray sum equal with K in c++
- Category
- C++
- Title
- newline in c++
- Category
- C++
- Title
- c++ try
- Category
- C++
- Title
- 2927260.eps 2927262.jpg 2927263.ai License free.txt License premium.txt
- Category
- C++
- Title
- insert at position in vector c++
- Category
- C++
- Title
- c++ ambigous error
- Category
- C++
- Title
- screen record ios simulator
- Category
- C++
- Title
- switch c++
- Category
- C++
- Title
- recursion in cpp with reference
- Category
- C++
- Title
- run cmd command c++
- Category
- C++
- Title
- find_if c++
- Category
- C++
- Title
- switch statement c++
- Category
- C++
- Title
- c++ cli convert string to string^
- Category
- C++
- Title
- sieve of eratosthenes c++
- Category
- C++
- Title
- c++ sort vector of objects by property
- Category
- C++
- Title
- % operator in c++
- Category
- C++
- Title
- c++ convert const char* to LPCWSTR
- Category
- C++
- Title
- how to make a switch case statement in c++
- Category
- C++
- Title
- object reference not set to an instance of an object c#
- Category
- C++
- Title
- create new file c++
- Category
- C++
- Title
- change int to string cpp
- Category
- C++
- Title
- c++ code for polynomial addition
- Category
- C++
- Title
- getting a random letter in c++
- Category
- C++
- Title
- memcmp in cpp
- Category
- C++
- Title
- popualte an array c++
- Category
- C++
- Title
- c++ get last element in vector
- Category
- C++
- Title
- lopping over an array c++
- Category
- C++
- Title
- iterative inorder traversal
- Category
- C++
- Title
- c++ how to add something at the start of a vector
- Category
- C++
- Title
- c++ allocate dynamic with initial values
- Category
- C++
- Title
- c++ public inheritance not getting protected
- Category
- C++
- Title
- pair in c++
- Category
- C++