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

C++ 字符串类型有关问题

2012-11-15 
C++ 字符串类型问题C/C++ code#include stdafx.h#include vector #include string #include ios

C++ 字符串类型问题

C/C++ code
#include "stdafx.h"#include < vector >#include < string >#include < iostream >using namespace std;struct Str{    char name1[100];    char name2[100];};void HandleStr( vector<Str*>&strTest ,string &outStr ){    string temp;    for( vector<Str*>::iterator it = strTest.begin(); it != strTest.end(); ++it )    {        if( it == strTest.begin() )        {             temp = (*it)->name1 + " =  '"+ (*it)->name2 + "'";             outStr += temp;        }        else        {             temp = " and " + (*it)->name1 + " =  '"+ (*it)->name2 + "'"             outStr += temp;        }    }}

报错是
1>d:\c++\handlestrtest\handlestrtest\handlestrtest.cpp(23) : error C2110: “+”: 不能添加两个指针
1>d:\c++\handlestrtest\handlestrtest\handlestrtest.cpp(28) : error C2110: “+”: 不能添加两个指针
怎么处理?

[解决办法]
这样:
string("aaa") + string("bbb")
不要这样:
"aaa" + "bbb"
[解决办法]
temp =
C/C++ code
(*it)->name1 

热点排行