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