c# - C++ 在 C# 中有类似 List<string> 的东西吗?

标签 c# c++

C++ 有类似 List<> 的东西吗?在 C# 中?类似于 List<string>用于存储字符串数组。

最佳答案

答案其实是

std::vector<std::string>

std::list是一个链表,而不是像 C# 的 List<T> 这样的数组类。

例如

#include <iostream> // iostream is for cout and endl; not necessary just to use vector or string
#include <vector>
#include <string>
using namespace std;

int main()
{
    vector<string> list;
    list.push_back("foo");
    list.push_back("bar");
    for( vector<string>::const_iterator it = list.begin(); it != list.end(); ++it )
        cout << *it << endl;

    return 0;
}

std::list class 实际上等同于 C# 的 LinkedList<T>类。

关于c# - C++ 在 C# 中有类似 List<string> 的东西吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6320622/

相关文章:

c++ - 如何手动设置使用哪个版本 'libstdc++.so.6' 而不是使用最新版本?

c++ - vim ctag 导致 fun 的错误定义

c# - 如何模仿 LabelFor 的 aspnet mvc 代码?

c# - WPF 数据绑定(bind)不填充选项卡?

c# - 使用 SoundPlayer() 播放多个 wav 文件而不重叠声音

c++ - 从 8 个连接的像素列表中提取片段

c++ - 通过将最小的数字放在第一位来将两个数组组合成一个

c# - 来自 Silverlight 应用程序的 WCF 自定义身份验证

c# - 从另一个单选按钮的 "CheckedChanged"事件中取消选择其他单选按钮

c++ - 在编译时强制执行正确的状态转换