error C3861: “make_tuple”: 找不到标识符

博客指出在使用C++11的tuple时,需要增加头文件#include <tuple>,为相关编程操作提供了必要的信息。

需要增加头文件

#include <tuple>

#pragma once #include"include.hpp" #include <stdexcept> enum choice { R = 0,V,I,C,L,运放 }; enum u_c { cons,mul }; #define M_PI 3.1415926 // 基类定义(扩展虚函数) class Electronic_Components { public: std::tuple<choice, double, u_c> 迪迦; // 元器件状态 // 虚析构函数确保正确释放派生类资源[^1] virtual ~Electronic_Components() = default; // 虚函数接口 virtual double get_value() const { return std::get<1>(迪迦); } virtual void set_value(double val) { std::get<1>(迪迦) = val; } }; // 电阻派生类(基类) class Resistor : public Electronic_Components { public: Resistor(double resistance, u_c variability) { 迪迦 = std::make_tuple(choice::R, resistance, variability); } }; // 不变电阻 class ConstantResistor : public Resistor { public: explicit ConstantResistor(double resistance) : Resistor(resistance, u_c::cons) { } // 成员初始化列表调用基类构造[^1] // 禁止修改值 void set_value(double) override { throw std::runtime_error("常量电阻值不可修改"); } }; // 可变电阻 class VariableResistor : public Resistor { public: explicit VariableResistor(double initial_resistance) : Resistor(initial_resistance, u_c::mul) { } // 允许修改值 void set_value(double new_resistance) override { if (new_resistance <= 0) { throw std::invalid_argument("电阻值必须为正数"); } Resistor::set_value(new_resistance); // 调用基类方法[^2] } }; // 电压源 class VoltageSource : public Electronic_Components { public: explicit VoltageSource(double voltage) { 迪迦 = std::make_tuple(choice::V, voltage, u_c::cons); } }; // 电流源 class CurrentSource : public Electronic_Components { public: explicit CurrentSource(double current) { 迪迦 = std::make_tuple(choice::I, current, u_c::cons); } }; // 电容 class Capacitor : public Electronic_Components { public: explicit Capacitor(double capacitance) { 迪迦 = std::make_tuple(choice::C, capacitance, u_c::mul); } // 添加电容特有方法 double get_impedance(double frequency) const { return 1.0 / (2 * M_PI * frequency * get_value()); } }; // 电感 class Inductor : public Electronic_Components { public: explicit Inductor(double inductance) { 迪迦 = std::make_tuple(choice::L, inductance, u_c::mul); } // 添加电感特有方法 double get_impedance(double frequency) const { return 2 * M_PI * frequency * get_value(); } }; class point { public: Electronic_Components 节点元器件; double V_in; double V_out; std::list<double> I_in; std::list<double> I_out; point(){} }; class edge { int from; int end; }; using boost::vecS; typedef boost::adjacency_list<vecS, vecS, boost::undirectedS, point, edge> elec_graph; class elec { elec_graph 蔡徐坤;//图对象 };把元器件看成一个特殊节点,补全point和edge
11-04
#include <iostream> #include <map> #include <string> #include <filesystem> using namespace std; // 添加该语句,将标准C++库中的所有标识符引入到当前的命名空间中[^1] namespace fs = std::filesystem; std::map<std::string, std::map<std::string, int>> countFileTypes(const std::string& path) { std::map<std::string, std::map<std::string, int>> stats; try { for (const auto& entry : fs::recursive_directory_iterator(path)) { if (entry.is_regular_file()) { std::string ext = entry.path().extension().string(); if (ext.empty()) { ext = "其他类型"; } stats[ext]["count"]++; } } } catch (const fs::filesystem_error& e) { std::cerr << "访问目录出错: " << e.what() << std::endl; } return stats; } int main() { std::string directoryPath = R"(C:\Users\s'y'r\Desktop\作业\文件类型统计\test-cs)"; auto fileStats = countFileTypes(directoryPath); std::cout << "{\n"; bool first = true; for (const auto& [ext, info] : fileStats) { if (!first) std::cout << ",\n"; std::cout << " \"" << ext << "\": {\"count\": " << info.at("count") << "}"; first = false; } std::cout << "\n}\n"; return 0; } 语法错误: 缺少“;”(在“:”的前面) 语言功能 "结构化绑定" 需要编译器标志 "/std:c++17" 语法错误: 缺少“;”(在“)”的前面) 语法错误: 缺少“,”(在“&”的前面) 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int 未定义标识符 "info" 未定义标识符 "ext" 应输入标识符 应输入“]” 命名空间 "std" 没有成员 "filesystem" 后面有“::”的名称一定是类名或命名空间名 后面有“::”的名称一定是类名或命名空间名 “recursive_directory_iterator”: 不到标识符 “operator <<”不明确 “fs”: 不是类或命名空间名称 “fs”: 不是类或命名空间名称 “filesystem”: 该名称的命名空间或类不存在 “e”: 未声明的标识符 “entry”: 类型包含“auto”的符号必须具有初始值设定项 “entry”: 必须初始化引用 "filesystem": 不是 "std" 的成员。 为什么报错,修改报错
最新发布
11-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值