从VS6到VS2010的ostringstream转换

时间:2012-05-16 14:23:42

标签: c++ ostringstream

我有这个代码在VS6下运行良好,但在VS2010中给我错误:

void CGreatString::operator>> (char * lpszDest)
{
strcpy (lpszDest, str());
rdbuf()->freeze(0);
}

我发现this 类似于我的问题,但它仍无效......

所以根据我的理解,ostrstream在VS2010中已被弃用,所以我尝试了这个:

void CGreatString::operator>> (char * lpszDest)
{
ostringstream os;
string str = os().str();                     //Error 1 and 2
strcpy (lpszDest, str.c_str());
os.rdbuf()->freeze(0);                       //Error 3
}

但我仍然会遇到错误:

1-错误C2064:术语不评估为采用0参数的函数

2-错误C2228:'。str'的左边必须有class / struct / union

3-错误C2039:'冻结':不是'std :: basic_stringbuf< _Elem,_Traits,_Alloc>'

的成员

谢谢!

2 个答案:

答案 0 :(得分:0)

根据对我的问题的评论,我已经能够纠正它。谢谢!

void CGreatString::operator>> (char * lpszDest)
{
    ostringstream os;
    string str = os.str();
    strcpy (lpszDest, str.c_str());
}

答案 1 :(得分:0)

因此迷你降价在评论中不起作用。太好了,那只是感激不尽。

void CGreatString::operator>> (char * lpszDest)
{
    // copy lpszDest into my CGreatString
    // The code you write does nothing at all.
}