c,c++怎么输入带空格的字符串?回车结束输入的那种,急求,跪谢,必采纳~谢谢

2025-03-02 17:02:30
推荐回答(1个)
回答1:

方法之一:

//#include "stdafx.h"//vc++6.0加上这一行.
#include 
#include 
using namespace std;
int main(void){
    string s;
    char ch;
    while(ch=cin.get(),ch!='\n')
        s+=ch;
    cout << s << endl;
    return 0;
}