从文件读取到 Listview C++ 时如何拆分文本?

How to split text when read from file to Listview c++?

此代码显示 ListView 第一列中的所有文本,但我需要按列拆分它。我试图在 ReadLine() 之后写 Split('|') 但它给出了一个错误。

    String^ textFile = String::Concat("C:\p.txt");
    StreamReader^ reader = gcnew  StreamReader(textFile);
    do
    {
        listView1->Items->Add(reader->ReadLine());

    } while (reader->Peek() != -1);

您需要单独添加子项目。所以你还需要在添加之前拆分字符串......

String^ stitems[] = reader->ReadLine()->Split('|');

ListViewItem^ item1 = gcnew ListViewItem( "item1",0 );
for each (String^ x in stitems) item1->SubItems->Add(x);

这里有一个很好的 c++/cli 示例...MSDN