关于std::vector<std::string>的操作
知识点
1 std::vector<std::string> 作为返回参数
void GetConfigState(std::vector<std::string>&vtTemp)
2 对于std::vector<std::string>取值操作
std::vector<std::string>::iterator theIterator;
for( theIterator = vtTemp.begin(); theIterator != vtTemp.end(); theIterator++ )
cout<<theIterator->c_str()<<endl;//这样取值
3 不能直接进行容器间赋值
#include <iostream> #include <vector> using namespace std; void GetConfigState(std::vector<std::string>&vtTemp) { unsigned int nLen = 0; unsigned int nValue = 0; std::string strType_Item; std::string strType_Items; std::string strTemp ="AT+CFUN=1;AT+CFUN=0"; int nPos = strTemp.find(";",0); int j = 0; while (nPos != -1) { vtTemp.push_back(strTemp.substr(0,nPos)); nPos ++; strTemp = strTemp.substr(nPos,strTemp.length() - nPos); nPos = strTemp.find(",",0); j++; } if (strTemp.length() != 0) { vtTemp.push_back(strTemp.c_str()); } } int main() { std::vector<std::string> vtTemp; std::vector<std::string>::iterator theIterator; GetConfigState(vtTemp); for( theIterator = vtTemp.begin(); theIterator != vtTemp.end(); theIterator++ ) cout<<theIterator->c_str()<<endl; getchar(); return 0; }