从STL复制函数以打印出矢量
Copy function from STL to print out vector
我正在尝试从STL打印出具有复制功能的矢量元素。理论上它应该在没有任何故障的情况下工作,但我收到了奇怪的通知,我在谷歌上搜索了一下,但我真的不明白我出了什么故障。让我展示一下我在做什么:
#include <iostream>
#include <vector>
int main(void)
{
vector<string> names;
names.push_back("Jeremy");
names.push_back("James");
names.push_back("Richard");
copy(names.begin(), names.end(), ostream_iterator<string>(cout, ' ');
// this line cause some problems;
}
我得到以下错误:
从const char*"到char"的转换无效
我很想得到一些适当的(也很容易理解的)解释我的想法有什么问题;)
干杯!
1.更改:
copy(names.begin(), names.end(), ostream_iterator<string>(cout, ' ');
进入:
copy(names.begin(), names.end(), ostream_iterator<string>(cout, " "));
(字符串文字,而非字符)
2.添加缺失的paren。
3.并添加丢失的<algorithm>
、<iterator>
和<string>
报头。
4.添加using namespace std;
相关文章:
- 我们如何打印出C++ STL 容器的value_type?
- 使用 Boost HOF 实现 STL 漂亮打印
- 无法在STL中打印一组矢量的元素
- 当遇到不是来自 STL 的未捕获异常时,有没有办法打印其信息?
- c++ stl 如何unordered_map打印其所有值?
- 打印/修改类对象的特定成员变量,其类定义列表 (STL) 包含的元素类型
- 从 STL 优先级队列C++ (QtCreator) 打印结构
- 如何在 STL 中使用reverse_iterator打印单词
- 使用队列和列表 STL 进行C++分配。在将数据填充到列表或队列中然后打印该数据时遇到问题
- 漂亮的打印不适用于C ++ STL列表
- 打印列表列表C++ STL 列表
- 计算出现次数并使用C/STL打印顶部K
- C++打印 STL 列表上的数据
- 我可以用cout而不是迭代器循环打印STL映射吗?
- 以二进制模式打印到STL(立体光刻)文件
- STL正确使用find_if()打印奇数
- 打印任何STL容器
- 从STL复制函数以打印出矢量
- 如何迭代地打印SET (STL)中的元素
- c++:打印STL列表