【发布时间】:2015-02-02 03:58:26
【问题描述】:
我想读一个句子来解读,但是出了点问题。当我不输入任何字符时,它会打印出“The sentence is”和“Decoded sentence is”,但是当我输入一个或多个字符时,它只会坐在那里什么都不做。我不认为这可能是 MySentence 类的错误,因为它甚至不打印“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;
}
【问题讨论】:
-
您在输入字符后是否按回车键?
-
是的,它只是换了一个新行。
-
试试这个:
cout << "The sentence is " << s << endl; -
作为@n.m。意思是说,它有助于在执行可能挂起的语句之前刷新输出。
标签: c++