Hiya
I don't know what I'm doing wrong that getline() does not work for me. My program is not finished but this is what I got so far:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
struct Term {
string word;
string definition;
};
struct Dictionary {
vector<Term> term;
};
void helpFunction() {
cout << "You have the following three options to choose from. \n" <<
"Note: Case sensitive, type them as exactly as they appear: \n" << endl;
cout << "Type 'Search' at anytime to search for a word "<< endl;
cout << "Type 'Help' at anytime to see the menu options again"<< endl;
cout << "Type 'Exit' at anytime to exit the program"<< endl;
}//end help
void infoFunction() {
cout << "Welcome to the best Dictionary program ever...EVER! \n" << endl;
cout << "Use this program to find a word and its definition. If the word is not in the library, you will be asked to update the library. \n" << endl;
cout << "You have the following three options to choose from. \n" <<
"Note: Case sensitive, type them as exactly as they appear: \n" << endl;
cout << "Type 'Search' at anytime to search for a word"<< endl;
cout << "Type 'Help' at anytime to see the menu options again"<< endl;
cout << "Type 'Exit' at anytime to exit the program"<< endl;
} // info function
void programLoop() {
//variables to use for program
string userInputString = "";
string searchString = "Search";
string helpString = "Help";
string exitString = "Exit";
infoFunction();
do {
cin >> userInputString; //get string input
if ( userInputString.compare(searchString) == 0 ) { //search for word
string userDefinition;
string userWord;
Dictionary myDictionary;
bool matchFound = false;
if ( myDictionary.term.size() == 0 ) {//assume no words in dictionary
cout << "Input the first word into the dictionary: ";
getline (cin,userWord);
cout << userWord << " .\n";
} //end find word section
if ( userInputString.compare(helpString) == 0 ) //help menu
{
helpFunction();
}
if ( userInputString.compare(exitString) == 0 ) //exit
{
exit(0);
}
} while ( userInputString.compare(searchString) == 0 || userInputString.compare(helpString) == 0 || userInputString.compare(exitString) == 0 );
} // program loop
void main()
{
programLoop();
system("pause");
} //end main
My cout of userWord is just to see if getline is working...which is not for some reason :( The funny thing is I know getline should work! I have already wrote a small little program (thats rather useless) to test it out (see below)I'm baffled by this. There must be something I'm not seeing or are not aware off Any help appreciated. :(
This works:
#include <iostream>
#include <string>
using namespace std;
void main() {
string str;
cout << "Please enter a word: ";
getline (cin,str);
cout << str << ".\n";
string def;
cout << "Please enter the definition: ";
getline (cin,def);
cout << str << " : " << def << ".\n";
system("pause");
} //end main