[英]error: could not convert 'tab' from 'vector<std::vector<std::__cxx11::basic_string<char> >>' to 'vector<std::__cxx11::basic_string<char>>'
here is my code which write a column j of a board t in an other board tab : I am a beginner so I don't understand the problem :(这是我的代码,它在另一个板选项卡中编写了板 t的列 j :我是初学者,所以我不明白这个问题:(
vector<string> colonne(vector<vector<string>> t, int j) {
vector<vector<string>>tab;
for(int i=0; i<t.size(); i++){
for(int n=0; n<=j; n++){
if(n == j){
tab[n]=t[j];
}
}
}
return tab;
}
here is the message from the terminal:这是来自终端的消息:
error: could not convert 'tab' from 'vector<std::vector<std::__cxx11::basic_string<char> >>' to 'vector<std::__cxx11::basic_string<char>>'
Your code has numerous problems.您的代码有很多问题。 I think (based on your description) that the code you are trying to write is this我认为(根据您的描述)您尝试编写的代码是这样的
vector<vector<string>> colonne(vector<vector<string>> t, int j) {
vector<vector<string>> tab(t.size());
tab[j]=t[j];
return tab;
}
The code above creates a new board tab
with the same number of columns as the first board.上面的代码创建了一个与第一个板具有相同列数的新板tab
。 It then copies one column (with index j
) from the first board to the second board and then returns the second board.然后它将一列(带有索引j
)从第一个板复制到第二个板,然后返回第二个板。
Notice though that all the other columns in the new board will have size zero.请注意,新板上的所有其他列的大小都将为零。 That seems strange to me, but maybe it is what you want.这对我来说似乎很奇怪,但也许这就是你想要的。 If not then let me know and I try to make improvements.如果没有,请告诉我,我会尝试改进。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.