【发布时间】:2021-03-17 22:28:52
【问题描述】:
我有一个程序加载一个选中的列表框,然后用户选择他们想要的项目并选择一个按钮说他们完成了。选中的项目在一个连续的字符串中读取,在每个字符串的末尾添加一个换行符“\n”。我的问题是除了换行符“\n”之外一切正常,我不知道为什么。
代码
private: System::Void bntSelected_Click(System::Object^ sender, System::EventArgs^ e) {
int numSelected = this->checkedListBox1->CheckedItems->Count;
if (numSelected != 0)
{
// Set input focus to the list box.
//SetFocus(lstReceiver);
String^ listBoxStr = "";
// If so, loop through all checked items and print results.
for (int x = 0; x < numSelected; x++)
{
listBoxStr = listBoxStr + (x + 1).ToString() + " = " + this->checkedListBox1->CheckedItems[x]->ToString() + "\n";
}
lstReceiver->Items->Add(listBoxStr);
}
}
【问题讨论】:
-
String^ listBoxStr这个怎么编译?你确定是 C++,而不是其他编程语言? -
“\n 不起作用”是什么意思?
-
是的,它是 C++ 并且通过 "\n" 不起作用,因为它不会在每次读取的末尾添加换行符。
-
也许您应该使用 Add 将字符串一一添加,而不是在添加之前将它们全部附加到一个长字符串中。
-
我一次加载一个,效果很好。
标签: c++-cli