首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

一个小程序,报些有关问题怪

2012-02-16 
一个小程序,报些问题怪!我写了个测试string属性的程序,可是,没想到这么个小程序,居然报个错误,不知道怎么

一个小程序,报些问题怪!
我写了个测试string属性的程序,可是,没想到这么个小程序,居然报个错误,不知道怎么处理,我的编译和链接都通过了,可是在执行的时候不行,visual   2005提示在运行的时候提示 "Unhandled   exception   at   0x7c812a5b   in   ttt.exe:   Microsoft   C++   exception:   std::bad_alloc   at   memory   location   0x0012f654.. "     我先把程序贴在下面,由于是第一次用stl的东西,是不是我露了些什么地方?     程序如下   :
#include   "stdafx.h "
#include   <string>
#include   <iostream>
#include   <algorithm>
#include   <vector>
#include   <fstream>

using   namespace   std;


int   _tmain(int   argc,   _TCHAR*   argv[])
{
string   temp= "test "   +   temp   +   "   to   it! ";
cout < <temp < <endl;
return   0;
}
期待各位的回答,先谢过了!


[解决办法]
string temp= "test " + temp + " to it! ";
==》
string temp= temp;
==》
string temp(temp);

够狠!
[解决办法]
string temp= "test " + temp + " to it! "; // 调用temp的ctor之前就用到了temp

热点排行