33,311
社区成员
发帖
与我相关
我的任务
分享
while (true)
{
cout << "input:";
string strIn;
std::getline(cin, strIn);
if (strIn.size() > 20)
{
cout << "size > 20" << endl;
}
else
{
cout << strIn << endl;
break;
}
}
不需要for循环:#include<iostream> using namespace std; #define MAX_INPUT_LEN 10 int main() { char input[MAX_INPUT_LEN]; cin.getline(input, MAX_INPUT_LEN); cout<<input<<endl; return 0; }
请问具体怎么实现呢 我想让用户输入一个字符串 但是不知道这个串能有多长 [quote=引用 1 楼 OrdinaryCoder 的回复:]那你应该用缓冲区的length来做for循环的次数
不需要for循环:#include<iostream> using namespace std; #define MAX_INPUT_LEN 10 int main() { char input[MAX_INPUT_LEN]; cin.getline(input, MAX_INPUT_LEN); cout<<input<<endl; return 0; }
请问具体怎么实现呢 我想让用户输入一个字符串 但是不知道这个串能有多长 那你应该用缓冲区的length来做for循环的次数
#include<iostream>
using namespace std;
#define MAX_INPUT_LEN 10
int main()
{
char input[MAX_INPUT_LEN];
cin.getline(input, MAX_INPUT_LEN);
cout<<input<<endl;
return 0;
}
请问具体怎么实现呢 我想让用户输入一个字符串 但是不知道这个串能有多长 那你应该用缓冲区的length来做for循环的次数
那你应该用缓冲区的length来做for循环的次数