在C ++中连接stringstream [英] concatenate stringstream in c++
本文介绍了在C ++中连接stringstream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何连接两个字符串流?
How can I concatenate two stringstreams?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include "types.h"
int main () {
char dest[1020] = "you";
char source[7] = "baby";
stringstream a,b;
a << source;
b << dest;
a << b; /*HERE NEED CONCATENATE*/
cout << a << endl;
cout << a.str() << endl;
return 0;
}
两次尝试的输出如下:
0xbf8cfd20
baby0xbf8cfddc
所需的输出是 babyyou
。
推荐答案
应为:
b << dest;
a << b.str();
stringstream :: str
返回 stringstream
。
这篇关于在C ++中连接stringstream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文