The following is part of my code which is a solution that i am trying to come up with for one of my book exercises...When i try to compiling this it skips both the request to get input for fram and to output fram.It just skips the 2 requests and goes on to print "joe" .Can anyone tell me what is happening?
#include <iostream>
#include <vector>
#include <string>
#include "Framer.h"
int main()
{
std::vector<std::string> sentences;
std::string s;
std::cout<<"The following program will take an input of strings and frame \n""it accroding to the users desires "<<std::endl;
std::cout<<"Please enter your set of sentences :"<<std::endl;
while(getline(std::cin, s)){
sentences.push_back(s);
}
std::cout<<"Please choose your method of framing. Enter center, left, or right"<<std::endl;
std::string fram;
std::cin>>fram;
std::cout<<fram;
std::cout<<"Joe"<<std::endl;
}
With ctrl+z (windows), the standard input stream goes into an eof (end of file) state; it won't read anything more (unless it comes out of that state).
#include <iostream>
#include <vector>
#include <string>
int main()
{
std::vector<std::string> sentences;
std::string s;
std::cout << "The following program will take an input of strings and frame \n""it according to the users desires \n""Please enter your set of sentences\n""enter an empty string (just hit enter) to end the input:\n" ;
while( std::getline(std::cin, s) && !s.empty() ){
sentences.push_back(s);
}
std::cout << "Please choose your method of framing. Enter center, left, or right\n" ;
std::string fram;
std::cin >> fram;
std::cout << fram;
}