ostringstream问题与int在c ++ [英] ostringstream problem with int in c++

查看:133
本文介绍了ostringstream问题与int在c ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望下面的代码输出 hello5 。相反,它只输出 hello
这似乎是一个问题,试图输出一个int到 ostringstream
当我直接输出到 cout 时,我收到预期的输入。在雪豹上使用XCode 3.2。

I would expect the following code to output hello5. Instead, it only outputs hello. It seems to be a problem with trying to output an int to the ostringstream. When I output the same directly to cout I receive the expected input. Using XCode 3.2 on Snow Leopard.

谢谢!

#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main(){
 int myint = 5;
 string mystr = "hello";
 string finalstr;
 ostringstream oss;

 oss << mystr << myint;
 finalstr = oss.str();

 cout << finalstr;


 return 0;
}

编辑:这似乎是由雪豹XCode 3.2中的活动配置'调试'中的问题创建的

推荐答案

将XCode中的活动配置从调试更改为释放可用作解决方法。

Changing the Active Configuration in XCode from 'Debug' to 'Release' works as a workaround.

这篇关于ostringstream问题与int在c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆