0

I am trying to read in a sentence to unscramble, however something is going wrong. When I enter no character it'll print out "The sentence is" and "Decoded sentence is", but when I enter one or more characters it'll just sit there and do nothing. I don't think it could be an error with MySentence class because it does not even print "The sentence is".

#include <iostream>
#include <stdio.h>
#include "MySentence.h"
#include "Corpus.h"
#include <string>
using namespace std;

int main() {
    Corpus corp;
    std::cout << "The proportions are: ";
    for(int i = 0; i<26; i++) {
            cout << corp.proportion(i+97) <<", ";
    }
    cout << endl;
    cout << "Enter sentence terminated by <ENTER> ";

    string s= "";
    getline(cin, s);
    cout << "The sentence is " << s;
    MySentence sent(s);
    sent.decode(corp);
    cout << endl << "Deoded sentence is: " << sent.sentence;
    return 0;
}
vchee
  • 11
  • 1

1 Answers1

0

As suggested by n.m. try to add an endl at the end of the line

cout << "The sentence is " << s << endl;

since it is possible that the buffer is not being flushed and the problem is in the class MySentence.

An interesting post that might help would be Buffer flushing: "\n" vs. std::endl

Community
  • 1
  • 1
Tomer G
  • 672
  • 6
  • 8
  • Ok that worked a little. It prints "The sentence is " plus whatever I enter but stops there. It never gets to "Decoded sentence..." – vchee Feb 02 '15 at 04:28
  • Have you tried using a debugger (e.g. gdb) to step through the code and see where it is hanging? – jjaguayo Feb 02 '15 at 06:11