String 从字符串vecotr获取值并存储在另一个字符串中?

String 从字符串vecotr获取值并存储在另一个字符串中?,string,visual-c++,vector,stl,mfc,String,Visual C++,Vector,Stl,Mfc,我试图将字符串值存储到vector中。然后在存储之后,我想一个接一个地存储在字符串中。在第一步中,通过“,”分割刺并存储到向量中。然后再次尝试重试并进入字符串 我的代码: CString sAssocVal = "test1, test2, test3"; istringstream ss( sAssocVal.GetBuffer(sAssocVal.GetLength()) ); vector<string> words; string token; while( std:

我试图将字符串值存储到vector中。然后在存储之后,我想一个接一个地存储在字符串中。在第一步中,通过“,”分割刺并存储到向量中。然后再次尝试重试并进入字符串

我的代码:

CString sAssocVal = "test1, test2, test3";

istringstream ss( sAssocVal.GetBuffer(sAssocVal.GetLength()) );

vector<string> words;


string token;
while( std::getline(ss, token, ',') )
{
    words.push_back( token );
}
CString sAssocVal=“test1、test2、test3”; istringstream ss(sAssocVal.GetBuffer(sAssocVal.GetLength()); 向量词; 字符串标记; while(std::getline(ss,token,,')) { 字。推回(代币); } 尝试再次从矢量检索:

for(int i = 0; i<words.size(); i++)
        std::string st= words[i];

for(int i=0;iAFAIK问题是istringstream初始化,一个小的修改使您的示例工作:


您可以首先将CString转换为std::string,关于这个问题有很多主题

我通过使用这段代码解决了这个问题

   CString st;
    for(int i = 0; i<words.size(); i++)
            st= words[i].c_str();
CString-st;

对于(int i=0;i)在循环之前,您是否尝试过调试和检查向量包含的内容?您所说的“获取NULL”是什么意思?您是如何观察到这一点的?我总是尽可能避免使用MFC的
CString
,问题可能在于您构建
istringstream
,您是否尝试过输出
ss.str()