c++ - 初始化具有动态长度的 vector

标签 c++ vector

能否请您告诉我如何将 buf vector 的大小更改为动态长度?

long five = 555;
char buf[256];
snprintf(buf, sizeof(buf), "%d", five); 

谢谢!

如何使用 std::vector<std::string>buf; 更改我的代码才能正常工作?
我有错误:

vector is not a member of std;
buf was not declared in this scope and error: expected primary-expression before ">" token

最佳答案

在 C++ 中,你不能。您将不得不以某种方式动态分配它,或者更好的是仍然使用像 std::vector 这样的动态数据结构。

关于c++ - 初始化具有动态长度的 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6018254/

上一篇:c++ - 单链表 C++

下一篇:c++ - 方向到角度

相关文章:

c++ - 预编译头的原始文件名

c++ - std::for_each 在具有两个参数的成员函数上的用法

c++ - vector 、指针、类和 EoF 循环 (C++)

c++ - 如何强制 vector 不可变?

c++ - 使用cmd通过ftp传输文件

c++ - 我可以专门研究前向声明的模板吗?

c++ - 在 C++ 中删除匿名对象

c++ - 为什么通过引用返回 vector 比通过 move 返回快得多?

c++ - map<string, vector<string>> vector 值的重新赋值

c++ - lseek 在 Windows 中使用 2 GB 文件