【发布时间】:2010-02-04 03:57:24
【问题描述】:
我有一个字符串数组,需要获取子字符串(在本例中是逗号之间的字符串)并将它们放入另一个字符串数组中。
我将其声明为strings[numberOfTapes],因此当我搜索逗号时,我会在嵌套的 for 循环中逐个字符地查找,如下所示:
for(int j = 0; j < tapes[i].length(); j++){
if(tapes[i][j] == ','){
input[counter2] = tapes[i][j].substr(i-counter, counter);
}
}
我收到以下错误:
对 tapes[i].std::basic_string::operator[] 中成员 'substr' 的请求 [与 _CharT = char,_Traits = std::char_traits,_Alloc = std::allocated] (((long unsigned int)))',属于非类类型'char'
我正在使用j 逐个字符地遍历字符串。有没有办法让.substr 使用tapes[i][j] 格式,还是我需要以不同的方式实现它才能工作?
【问题讨论】:
标签: c++