我编写了一个以name
和dessert
为输入而不是输出的程序。我想使用get()
函数进行此操作。我使用MinGW编译器在Eclipse Mars C ++中编程。当我尝试运行程序时会弹出一条警告消息,说明程序中存在错误,尽管它没有显示错误的位置,之后没有任何反应。看看下面的代码 -
#include <iostream>
#include <cstring>
using namespace std;
int main() {
const int ArSize=15;
char name[ArSize];
char dessert[ArSize];
cin.get(name, ArSize); // read first line
cin.get(); // read newline
cin.get(dessert, ArSize); // read second line
cin.get(); // read newline
cout<<name<<endl<<dessert;
return 0;
}
答案 0 :(得分:0)
只是猜测,但除非您还有std::endl
,否则无法定义#include <iomanip>
。但是请不要添加#include
指令:您不需要std::endl
,只需'\n'
即可。正如在书中......
答案 1 :(得分:0)
我不知道我的代码现在如何运行。我卸载了MinGW,然后安装了MinGW_w64。我怀疑我以前版本的MinGW与我的Windows不兼容,因为它可能是32位。 但毕竟我的代码现在运行良好。