<分区>
这里是代码,我用的是Codeblocks,miwGW编译器
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
int L; char sir[100];
cin>>L;
cin.getline(sir,100);
return 0;
}
读取 L 值后,执行就停止了,我无法再读取 char 变量“sir”。为什么?
标签 c++ return codeblocks
<分区>
这里是代码,我用的是Codeblocks,miwGW编译器
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
int L; char sir[100];
cin>>L;
cin.getline(sir,100);
return 0;
}
读取 L 值后,执行就停止了,我无法再读取 char 变量“sir”。为什么?
最佳答案
使用
#include <limits>
//...
std::cin>>L;
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
//...
关于c++ - 奇怪的执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58711262/