为什么我不能有矢量< string []>? [英] Why can't I have a vector<string[]>?
问题描述
你好,
我是C ++的新手。我知道原因可能是模板实例化
问题...但是*真实的原因我不能声明:
vector< string [] v = vector< string []>(4);
谢谢!
- 沙菲克
Shafik写道:
你好,
我是C ++的新手。我知道原因可能是模板实例化
问题...但是*真实的原因我不能声明:
vector< string [] v = vector< string []>(4);
向量的类型(即向量中的T< T>)需要支持复制。
标准不允许复制数组。
即
int a [2];
int b [2];
b = a; //不允许。
你遇到的另一个问题是string []并不是一个完全
定义的类型(即没有大小)。
试试这个:
vector< vector< string v = vector< vector< string [](4);
4月28日下午4:44,Shafik< shafi ... @ gmail.comwrote:
< blockquote class =post_quotes>
你好,
我是C ++的新手。我知道原因可能是模板实例化
问题...但是*真实的原因我不能声明:
vector< string [] v = vector< string []>(4);
谢谢!
--Shafik
string []意味着什么都没有,没有像
没有固定常量大小的数组。
std :: vector需要copy-constructeable和assigneable elements
(这就是法律)。
此外,为什么你会想要一个矢量< string [const size_t]>?
自:
std :: vector<的std ::矢量< std :: string vvs;
你想要存储字符串数组的向量吗,对吧?
也许这可能有用你好
vector< string * var;
关于string [],我猜...通常我们在变量后使用[]来制作
它是一个数组,但字符串在技术上不可变;它是一个类。
Hello,
I am new to C++. I know the reason is probably template instantiation
problems ... but what''s the *real* reason I cannot declare a:
vector<string[]v = vector<string[]>(4);
Thanks!
--Shafik
Shafik wrote:Hello,
I am new to C++. I know the reason is probably template instantiation
problems ... but what''s the *real* reason I cannot declare a:
vector<string[]v = vector<string[]>(4);The type of a vector (i.e. T in vector<T>) needs to support copy. The
standard does not allow copy of arrays.
i.e.
int a[2];
int b[2];
b=a; // not allowed.
The other problem you have is that string[] is not really a fully
defined type (i.e. no size).
Try this:
vector< vector<string v = vector< vector<string[](4);
On Apr 28, 4:44 pm, Shafik <shafi...@gmail.comwrote:Hello,
I am new to C++. I know the reason is probably template instantiation
problems ... but what''s the *real* reason I cannot declare a:
vector<string[]v = vector<string[]>(4);
Thanks!
--Shafikstring[] means nothing at all, there is no such thing as an array with
no fixed constant size.
A std::vector requires copy-constructeable and assigneable elements
too (thats the law).
Besides, why would you ever want a vector< string[const size_t] >?
since:
std::vector< std::vector< std::string vvs;
Do you want vector that store array of string, right?
Maybe this may work of you
vector<string*var;
About string[], I guess ... usually we use [] after variable to make
it an array but string is techniquely not variable;it''s a class.
这篇关于为什么我不能有矢量< string []>?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!