从“char”转换为转换为非标量类型“Vector”抛出错误未知原因
抛出未知错误
#include "std_lib_facilities.h"
int main()
{
vector<char> shape = ('a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a');
return(0);
}
带有向量的一行抛出此错误的原因是我以前从未见过也无法弄清楚...
:: g++ TicTacToe.cpp -o TTT
TicTacToe.cpp:在函数int main()'中:
char' 到非标量类型“Vector”的转换 请
TicTacToe.cpp:5: 错误:请求从
参阅每个井字游戏框中,它将以 _ 开头,然后转到 X 或 O,I'我在没有图形库的情况下执行此操作,因此它是终端图形。
Error Thrown Unknown Reason
#include "std_lib_facilities.h"
int main()
{
vector<char> shape = ('a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a');
return(0);
}
that one line with the vector throws this error that I've never seen before nor can figure out...
:: g++ TicTacToe.cpp -o TTT
TicTacToe.cpp: In function int main()':
char' to non-scalar type `Vector' requested
TicTacToe.cpp:5: error: conversion from
See in each tic-tac-toe box it will start as _ and then go to either X or O, I'm doing this without a graphics library so its terminal graphics.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果所有值都相同,您可以使用 std::vector 的以下构造函数:
如果部分或所有值不同,您可以使用另一个构造函数,如下所示:
或者
If all value are the same you can use the following constructor of the
std::vector
:If part or all values are distinct you can use another constructor as follows:
Or
这种向量初始化在当前的 C++ 中是不可能的。您可以使用 :
来达到所需的效果(创建一个大小为 9 的向量,其中所有元素都设置为
'_'
)。如果 boost 是一个选项,Boost.Assign 提供了您最初想要实现的语法类型,尽管在这种特殊情况下使用适当的
std:: vector
构造函数基本上就足够了。Such vector initialization isn't possible in current C++. You can use :
which will have the desired effect (create a vector of size 9 where all elements are set to
'_'
).If boost is an option, Boost.Assign provides the kind of syntax you wanted to achieve initially, although in this particular case using the appropriate
std::vector
constructor is largely sufficient.Vector 没有这样的构造函数。请参阅有效的构造函数。
vector doesn't have such a constructor. See the valid constructors.
vector 类具有以下构造函数:
使用它您可以执行以下操作:
The vector class has the following constructor:
Using which you can do: