We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
这部分代码是不是应该加一个类型判断,否则K,V的类型未知,编译器无法通过
// 从文件读取数据 template<class K, class V> void SkipList<K, V>::load_file() { this->_file_reader.open("test.txt", ios::in); string line; while (getline(_file_reader, line)) { string key_str, value_str; get_key_value_from_string(line, &key_str, &value_str); if (key_str.empty() || value_str.empty()) { continue; } K key; V value; // 根据 K 的类型进行转换 if constexpr (is_same<K, int>::value) { key = stoi(key_str); } else if constexpr (is_same<K, double>::value) { key = stod(key_str); } else { key = key_str; // 假设 K 是 string } // 根据 V 的类型进行转换 if constexpr (is_same<V, int>::value) { value = stoi(value_str); } else if constexpr (is_same<V, double>::value) { value = stod(value_str); } else { value = value_str; // 假设 V 是 string } // 插入元素 insert_element(key, value); cout << "key: " << key << " value: " << value << endl; } _file_reader.close(); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
这部分代码是不是应该加一个类型判断,否则K,V的类型未知,编译器无法通过
The text was updated successfully, but these errors were encountered: