gpt4 book ai didi

c++ - 在 CStringArray 中从 5 个元素中选择 3 个元素?

转载 作者:行者123 更新时间:2023-11-30 05:44:45 25 4
gpt4 key购买 nike

在此代码中,keepSelectedFiles 有 5 个文本文件。我想选择其中的 3 个并添加到另一个数组 keepFiles 中。计数只是用户的输入。如果用户在文本框中选择 3,则计数为 3 任意数字等。

for (int i = 0; i < keepSelectedFiles.GetSize(); i++)
{
for (int i = 0; i < count; i++)
{
keepFiles.RemoveAt(keepFiles.IsEmpty());
keepFiles.Add(keepSelectedFiles[i]);
testbox6.AddString(keepFiles[i]);
}
}

请帮我看看我该怎么做?

最佳答案

这是实现它的方法(性能优化):

if (count < 0)
return; // error handling

if (count < keepSelectedFiles.GetSize())
{
keepFiles.SetSize(count);
for (int i=0; i<count; i++)
{
keepFiles[i] = keepSelectedFiles[i];
}
}
else
{
keepFiles.Copy(keepSelectedFiles);
}

关于c++ - 在 CStringArray 中从 5 个元素中选择 3 个元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29642574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com