c++string 输入换行符

c++string 输入换行符,第1张

换行符通常是默认的输入结束标志,现在要把它作为字符存入字符串,就得另外约定一个结束符,这里设为'#'。有了这个约定,就有很多办法可以解决题面问题,下面提供一种:

//#include "stdafx.h"//If the vc++6.0, with this line.

#include <string>

#include <iostream>

using namespace std

int main(void){

    string s

    char x

    while((x=cin.get())!='#')//输入#结束,其他字符继续

        s+=x

    cout << s << endl

    return 0

}

//#include "stdafx.h"//If the vc++6.0, with this line.

#include "stdio.h"

int main(void){

char a[]="1234567890",b[]="abcdefg"

printf("不添换行符:\n%s%s\n",a,b)

printf("不添换行符:\n%s\n%s\n",a,b)

return 0

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11926017.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存