当前位置: 首页 > news >正文

C++函数式策略模式中配置修改

在从面向过程.到面向对象,再到函数式策略模式的转变和精进时,

敲的代码编译运行不了,不支持多文件编译,分析定位后是之前的相关json 配置导致,修改如下:

一.原来配置

1.tasks.json

//tasks.json{"version": "2.0.0","tasks": [{"type": "cppbuild","label": "build","type": "shell","command": "D:/wecode_build_tools/mingw/bin/g++.exe","args": ["-g","${file}","-o","${fileDirname}/${fileBasenameNoExtension}"],"group": {"kind": "build","isDefault": true},"problemMatcher": ["$gcc"]}]}

2.settings.json

//settings.json{"files.associations": {"iostream": "cpp","array": "cpp","atomic": "cpp","*.tcc": "cpp","cctype": "cpp","clocale": "cpp","cmath": "cpp","cstdarg": "cpp","cstddef": "cpp","cstdint": "cpp","cstdio": "cpp","cstdlib": "cpp","cwchar": "cpp","cwctype": "cpp","deque": "cpp","unordered_map": "cpp","vector": "cpp","exception": "cpp","algorithm": "cpp","memory": "cpp","memory_resource": "cpp","optional": "cpp","string": "cpp","string_view": "cpp","system_error": "cpp","tuple": "cpp","type_traits": "cpp","utility": "cpp","fstream": "cpp","initializer_list": "cpp","iosfwd": "cpp","istream": "cpp","limits": "cpp","new": "cpp","ostream": "cpp","sstream": "cpp","stdexcept": "cpp","streambuf": "cpp","typeinfo": "cpp"},"files.encoding": "utf8","files.autoGuessEncoding": true,"terminal.integrated.shellArgs.windows": ["-NoProfile","-ExecutionPolicy","Bypass","-Command","chcp 65001"],"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe","terminal.integrated.shellArgs.windows": ["/k", "D:\\wecode_build_tools\\mingw\\bin\\mingw32-make.exe"]
}

二.修改版本

编译配置是否正确,特别是编译器路径和C++标准。之前的代码修复中使用了C++14的特性,比如std::make_unique,这是C++14引入的,而tasks.json中指定的是-std=c++11,这会导致编译错误,因为C++11不支持std::make_unique。这是一个关键问题,需要用户将C++标准升级到C++14或更高。

另外,检查settings.json中的终端参数是否正确。用户可能希望终端在编译后自动运行程序,但当前配置可能没有设置。可能需要添加运行可执行文件的步骤,或者在tasks.json中添加一个执行任务。

1.tasks.json

//tasks.json{"version": "2.0.0","tasks": [{"label": "Build and Run","type": "shell","command": "D:/wecode_build_tools/mingw/bin/g++.exe","args": ["-std=c++11","main.cpp","AcceptCash.cpp","-o","${fileDirname}/${fileBasenameNoExtension}.exe"],"group": {"kind": "build","isDefault": true},"presentation": {"echo": true,"reveal": "always","focus": false,"panel": "shared"},"problemMatcher": "$gcc"}]
}

2.settings.json

// settings.json{"files.associations": {"*.h": "cpp","*.hpp": "cpp","iostream": "cpp","array": "cpp","atomic": "cpp","*.tcc": "cpp","cctype": "cpp","clocale": "cpp","cmath": "cpp","cstdarg": "cpp","cstddef": "cpp","cstdint": "cpp","cstdio": "cpp","cstdlib": "cpp","cwchar": "cpp","cwctype": "cpp","deque": "cpp","unordered_map": "cpp","vector": "cpp","exception": "cpp","algorithm": "cpp","memory": "cpp","memory_resource": "cpp","optional": "cpp","string": "cpp","string_view": "cpp","system_error": "cpp","tuple": "cpp","type_traits": "cpp","utility": "cpp","fstream": "cpp","initializer_list": "cpp","iosfwd": "cpp","istream": "cpp","limits": "cpp","new": "cpp","ostream": "cpp","sstream": "cpp","stdexcept": "cpp","streambuf": "cpp","typeinfo": "cpp","random": "cpp","bit": "cpp","bitset": "cpp","chrono": "cpp","condition_variable": "cpp","cstring": "cpp","ctime": "cpp","list": "cpp","map": "cpp","set": "cpp","functional": "cpp","iterator": "cpp","numeric": "cpp","ratio": "cpp","regex": "cpp","future": "cpp","iomanip": "cpp","mutex": "cpp","shared_mutex": "cpp","thread": "cpp","cinttypes": "cpp","complex": "cpp","unordered_set": "cpp","cfenv": "cpp","typeindex": "cpp"},"files.encoding": "utf8","files.autoGuessEncoding": true,"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe","terminal.integrated.shellArgs.windows": ["/k","D:\\wecode_build_tools\\mingw\\bin\\mingw32-make.exe"],"C_Cpp.default.compilerPath": "D:/wecode_build_tools/mingw/bin/g++.exe","C_Cpp.default.cppStandard": "c++14","C_Cpp.default.cStandard": "c17","files.trimTrailingWhitespace": true,"editor.formatOnSave": true,"editor.codeActionsOnSave": {"source.organizeImports": true},"C_Cpp.intelliSenseEngine": "Default","C_Cpp.errorSquiggles": "Enabled","C_Cpp.autocomplete": "Disabled"
}

三.最终修改

我这本来编译就上午调好了,环境的也改的差不多了,改14版本后
用的是旧版配置键名 C_Cpp.default.*,但 VS Code 的 C/C++ 扩展(Microsoft C/C++)在新版中已经改用 C_C++(带加号)作为命名空间!

1.tasks.json

//tasks.json
{"version": "2.0.0","tasks": [{"label": "Build and Run","type": "shell","command": "D:/wecode_build_tools/mingw/bin/g++.exe","args": ["-std=c++14","main.cpp","AcceptCash.cpp","-o","${fileDirname}/${fileBasenameNoExtension}.exe","&&","${fileDirname}/${fileBasenameNoExtension}.exe"],"group": {"kind": "build","isDefault": true},"presentation": {"echo": true,"reveal": "always","focus": false,"panel": "shared"},"problemMatcher": {"owner": "cpp","fileLocation": ["relative","${workspaceFolder}"],"pattern": {"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$","file": 1,"line": 2,"column": 3,"severity": 4,"message": 5}}}]
}

2.settings.json

// settings.json
{"files.associations": {"*.h": "cpp","*.hpp": "cpp","iostream": "cpp","array": "cpp","atomic": "cpp","*.tcc": "cpp","cctype": "cpp","clocale": "cpp","cmath": "cpp","cstdarg": "cpp","cstddef": "cpp","cstdint": "cpp","cstdio": "cpp","cstdlib": "cpp","cwchar": "cpp","cwctype": "cpp","deque": "cpp","unordered_map": "cpp","vector": "cpp","exception": "cpp","algorithm": "cpp","memory": "cpp","memory_resource": "cpp","optional": "cpp","string": "cpp","string_view": "cpp","system_error": "cpp","tuple": "cpp","type_traits": "cpp","utility": "cpp","fstream": "cpp","initializer_list": "cpp","iosfwd": "cpp","istream": "cpp","limits": "cpp","new": "cpp","ostream": "cpp","sstream": "cpp","stdexcept": "cpp","streambuf": "cpp","typeinfo": "cpp","random": "cpp","bit": "cpp","bitset": "cpp","chrono": "cpp","condition_variable": "cpp","cstring": "cpp","ctime": "cpp","list": "cpp","map": "cpp","set": "cpp","functional": "cpp","iterator": "cpp","numeric": "cpp","ratio": "cpp","regex": "cpp","future": "cpp","iomanip": "cpp","mutex": "cpp","shared_mutex": "cpp","thread": "cpp","cinttypes": "cpp","complex": "cpp","unordered_set": "cpp","cfenv": "cpp","typeindex": "cpp"},"files.encoding": "utf8","files.autoGuessEncoding": true,"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe","terminal.integrated.shellArgs.windows": ["/k","D:\\wecode_build_tools\\mingw\\bin\\mingw32-make.exe"],"C_Cpp.default.compilerPath": "D:/wecode_build_tools/mingw/bin/g++.exe","C_Cpp.default.cppStandard": "c++14","C_Cpp.default.cStandard": "c17","files.trimTrailingWhitespace": true,"editor.formatOnSave": true,"editor.codeActionsOnSave": {"source.organizeImports": true},"C_Cpp.intelliSenseEngine": "default","C_Cpp.errorSquiggles": "enabled","C_Cpp.autocomplete": "disabled"
}

四.验证

最后使用的配置可以运行

1.方法1

g++ -std=c++14 -c main.cpp -o main.o #编译_方法1
./cash_program.exe #运行

2.方法2

D:/wecode_build_tools/mingw/bin/g++.exe -std=c++14 main.cpp AcceptCash.cpp -o cash_program.exe #编译_方法2
./cash_program.exe #运行

3.多文件编译

g++ -std=c++14 main.cpp MathUtils.cpp -o cash_program.exe #多文件编译
./cash_program.exe #运行

整理不易,诚望各位看官点赞 收藏 评论 予以支持,这将成为我持续更新的动力源泉。若您在阅览时存有异议或建议,敬请留言指正批评,让我们携手共同学习,共同进取,吾辈自当相互勉励!

http://www.dtcms.com/a/609200.html

相关文章:

  • [MCP][]快速入门MCP开发
  • 为食堂写个网站建设免费毕业设计的网站建设
  • 云原生数据平台(cloudeon)--核心服务组件扩展
  • 字典或者列表常用方法介绍
  • 计算机网络中的地址体系全解析(包含 A/B/C 类地址 + 私有地址 + CIDR)
  • SpringBoot教程(三十四)| SpringBoot集成本地缓存Caffeine
  • 专业摄影网站推荐专业做卖菜的网站
  • Hadess V1.2.5版本发布,新增推送规则、制品扫描等,有效保障制品质量与安全
  • 华清远见25072班单片机高级学习day1
  • Apache Flink运行环境搭建
  • Node.js(v16.13.2版本)安装及环境配置教程
  • Flutter 每日库: device_info_plus获取设备详细信息
  • 小马网站建设网站备案好
  • 做某网站的设计与实现网页设计代码案例
  • 生产级 Rust Web 应用架构:使用 Axum 实现模块化设计与健壮的错误处理
  • 大模型三阶段训练:预训练、SFT、RLHF解决的核心问题
  • 记/基准] RELIABLE AND DIVERSE EVALUATION OF LLM MEDICAL KNOWLEDGE MASTERY
  • TensorFlow深度学习实战(9)——卷积神经网络应用
  • LeetCode 分类刷题:203. 移除链表元素
  • 【Qt开发】Qt窗口(一) -> 菜单栏
  • Python的json模块和jsonpath模块
  • Crawl4ai 框架的学习与使用
  • hadoop节点扩容和缩容操作流程
  • RDF 与 RDFS:知识图谱推理的基石
  • 最新轻量版域名防红跳转源码 带后台 支持随机跳转有效放屏蔽
  • linux: udp服务器与客户端 CS 基于ipv4的地址结构体
  • 做食品网站需要什么条件手机靓号网站建设
  • 运筹说145期:从快递到自动驾驶:启发式算法的智慧幕后
  • 如何选择合适的养老服务机器人
  • 微博评论数据采集:基于Requests的智能爬虫实战