gpt4 book ai didi

c++ - 未定义模板 “std::__1::basic_istringstream, std::__1::allocator>”的隐式实例化

转载 作者:行者123 更新时间:2023-12-02 10:50:55 41 4
gpt4 key购买 nike

我正在学习C++并正在学习教程,但是在入门代码中构建代码时遇到了问题。

这是引发此错误的源代码文件。

#include "linux_parser.h"

#include <dirent.h>
#include <unistd.h>
#include <istream>
#include <string>
#include <vector>

using std::stof;
using std::string;
using std::to_string;
using std::vector;

// DONE: An example of how to read data from the filesystem
string LinuxParser::OperatingSystem() {
string line;
string key;
string value;
std::ifstream filestream(kOSPath);
if (filestream.is_open()) {
while (std::getline(filestream, line)) {
std::replace(line.begin(), line.end(), ' ', '_');
std::replace(line.begin(), line.end(), '=', ' ');
std::replace(line.begin(), line.end(), '"', ' ');
std::istringstream linestream(line);
while (linestream >> key >> value) {
if (key == "PRETTY_NAME") {
std::replace(value.begin(), value.end(), '_', ' ');
return value;
}
}
}
}
return value;
}

以下是我在Mac Catalina上本地运行 make build时引发的错误。
Scanning dependencies of target monitor
[ 12%] Building CXX object CMakeFiles/monitor.dir/src/format.cpp.o
[ 25%] Building CXX object CMakeFiles/monitor.dir/src/linux_parser.cpp.o
/Users/Documents/github/cpp/src/linux_parser.cpp:25:26: error: implicit instantiation of undefined template
'std::__1::basic_istringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >'
std::istringstream linestream(line);
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iosfwd:133:32: note: template is declared here
class _LIBCPP_TEMPLATE_VIS basic_istringstream;
^
/Users/Documents/github/cpp/src/linux_parser.cpp:44:24: error: implicit instantiation of undefined template
'std::__1::basic_istringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >'
std::istringstream linestream(line);
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iosfwd:133:32: note: template is declared here
class _LIBCPP_TEMPLATE_VIS basic_istringstream;
^
2 errors generated.
make[3]: *** [CMakeFiles/monitor.dir/src/linux_parser.cpp.o] Error 1
make[2]: *** [CMakeFiles/monitor.dir/all] Error 2
make[1]: *** [all] Error 2
make: *** [build] Error 2

最佳答案

您需要#include <sstream>才能使用std::istringstream

关于c++ - 未定义模板 “std::__1::basic_istringstream<char, std::__1::char_traits<char>, std::__1::allocator<char>>”的隐式实例化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61735609/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com