int read_input_string(char *filename, char *entry, char **data, int num){ifstream ifp(filename);char buffer[256];int entry_len = strlen(entry);int i, flag, idx, count = 0;while (ifp.getline(buffer, 256) != NULL){int buffer_len = strlen(buffer);if (buffer_len >= entry_len){flag = 1;for (i = 0; i<entry_len; i++)if (buffer[i] != entry[i]) flag = 0;if (flag == 1){while (buffer[i] != '=' && buffer[i] != '\0')i++;if (buffer[i] != '\0') i++;while (buffer[i] == ' ' && buffer[i] != '\0')i++;count = 0;idx = 0;for (int j = i; j <= buffer_len; j++){if (buffer[j] == ' ' || j == buffer_len){if (idx != 0){data[count][idx] = '\0';idx = 0;count++;if (count == num) break;}}elsedata[count][idx++] = buffer[j];}}}}if (count < num)return -1;elsereturn 0;}在这段C++程序里,调试时会提示如下错误:IntelliSense: 没有与这些操作数匹配的 "!=" 运算符操作数类型为: std::basic_istream<char, std::char_traits<char>> != int希望各位高手帮忙看看该怎么修改?
1 回答
慕仙森
TA贡献1827条经验 获得超8个赞
while (ifp.getline(buffer, 256) != NULL)
这行改成
ifp.getline(buffer, 256); while (ifp.good()) { //.... //... ifp.getline(buffer, 256); } |
因为getline函数返回的是ifp对象本身的应用,而不是读取到的字符数。
添加回答
举报
0/150
提交
取消