我有一个CString
像这样:
CString cstring = "Aaaa\nBadsalkjhf\nSM876\nSKSJDJHALSD";
如何添加每个CString并将这些项目作为列表添加到ComboBox(MFC,C ++)中。
答案 0 :(得分:1)
尝试以下代码段:
CStringA cstring = "Aaaa\nBadsalkjhf\nSM876\nSKSJDJHALSD";
// transfer to stringstream to ease splitting
std::stringstream ss;
ss << cstring.GetString();
std::string str;
// splitting using "\n" as the delimiter
while (std::getline(ss,str,'\n')) {
ComboBox.AddString(str.c_str());
}
已编辑:对于Unicode
#include<iostream>
#include<sstream>
#include"atlstr.h"
void main()
{
CStringW cstring = L"Aaaa\nBadsalkjhf\nSM876\nSKSJDJHALSD";
// transfer to stringstream to ease splitting
std::wstringstream ss;
ss << cstring.GetString();
std::wstring str;
// splitting using "\n" as the delimiter
while (std::getline(ss, str, L'\n')) {
ComboBox.AddString(str.c_str());
}
}