linux strstrea.h
hej jeg sidder paa min linux og er igang med en bog om OOP i C og der er include til denne fil strstrea.h men har den ikke og kan ikke helt finde noget om hvad jeg skalher er den h fil der er include til filen i:
//#include <strstream.h> fandt noget med man kunne bruge denne istedet men kan heller ikke finde den
#include <strstrea.h> // denne fil
#ifndef BOOLEAN
#define BOOLEAN
enum Boolean { false, true };
#endif
#ifndef menu_H
#define menu_H
const MAX_CONSOLE_MENU_SIZE = 10;
class Console_Menu {
public:
Console_Menu() { menu_size = 0; }
~Console_Menu() { }
void add_item(char* new_item);
void add_terminator(char* quit_label);
void add_prompt(char* menu_prompt);
void display_menu();
int get_user_selection();
int get_selection() { return selection; }
protected:
Boolean validate_selection(int selection);
char* menu_items[MAX_CONSOLE_MENU_SIZE];
char* prompt_string;
int menu_size;
int selection;
};
void Console_Menu::add_item(char* new_item)
{
char* menu_item;
char* item_string = new char[25];
sprintf(item_string, "%i. %s", menu_size+1, new_item);
menu_item = new char[strlen(item_string) + 1];
strcpy(menu_item, item_string);
menu_items[menu_size++] = menu_item;
delete[] item_string;
}
void Console_Menu::add_terminator(char* quit_label)
{
this->add_item(quit_label);
}
void Console_Menu::add_prompt(char* new_prompt)
{
prompt_string= new_prompt;
}
void Console_Menu::display_menu()
{
cout << endl;
for (int i = 0; i< menu_size; i++)
cout << menu_items[i] << endl;
cout << endl << prompt_string;
}
Boolean Console_Menu::validate_selection(int selection)
{
if((selection <= menu_size) && (selection > 0))
return true;
else
return false;
}
int Console_Menu::get_user_selection()
{
int choice, quit_choice = menu_size;
char choice_char;
Boolean valid_selection = flase;
while(!valid_selection)
{
this->display_menu();
cin.get(choice_char);
cin.ignore(100, '\n');
if (!isdigit(choice_char))
choice = 0;
else
choice = atoi(&choice_char);
if (!this->validate_selection(choice))
cout << "Invalid choice, try again." << endl;
else
valid_selection = true;
}
if(choice == quit_choice)
selection = 0;
else
selection = choice;
return selection;
}