C++通过cin.get()输入字符串



C++通过cin.get()输入字符串

#include <iostream>
#include <string>
using namespace std;

int main()
{

char str[10000];
char temp;
int len = 0;
cout << “输入:”;
while(1)
{
temp = cin.get();
if(temp != ‘\n’) str[len++] = temp;
else break;
}
cout << “输出:”;
for(int i = 0; i < len; ++i)
cout << str[i];
return 0;
}
通过cin.get() 获得单个字符,只要是字符都能输入,不至于碰到空格就停止

 

———————

本文来自 Chen-Lee 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/qq_16583687/article/details/77825475?utm_source=copy