new file: .vs/C demo.slnx/FileContentIndex/8a121676-540c-4c4c-bec5-f112761d8964.vsidx new file: .vs/C demo.slnx/FileContentIndex/afcad3e7-8738-4d7b-b381-8f48482cd11d.vsidx new file: .vs/C demo.slnx/FileContentIndex/b4eed3d7-5d85-46db-824b-5036316dde90.vsidx new file: .vs/C demo.slnx/FileContentIndex/e3b4053e-bac0-4801-86c7-806f66950eda.vsidx new file: .vs/C demo.slnx/config/applicationhost.config new file: .vs/C demo.slnx/copilot-chat/5ed72f75/sessions/40390e80-9500-4f58-ad64-714b8c7deac0 new file: .vs/C demo.slnx/v18/.wsuo new file: .vs/C demo.slnx/v18/Browse.VC.db new file: .vs/C demo.slnx/v18/DocumentLayout.backup.json new file: .vs/C demo.slnx/v18/DocumentLayout.json new file: .vs/C demo.slnx/v18/Solution.VC.db new file: .vs/C demo.slnx/v18/ipch/AutoPCH/2c405fb4c3583bf7/~MAIN.ipch new file: .vs/C demo.slnx/v18/ipch/AutoPCH/ca90bcb00f18b0c2/VWFNTCXL..ipch new file: ".vs/C demo.slnx/v18/ipch/AutoPCH/f4c5d32207939beb/\346\272\2203.ipch" new file: .vs/C demo/CopilotIndices/18.3.502.33069/CodeChunks.db new file: .vs/C demo/CopilotIndices/18.3.502.33069/SemanticSymbols.db new file: .vs/CopilotSnapshots/800E39400095584FAD64714B8C7DEAC0/23DA5FED92DF88449BA1921B5E7140E6/5DFE71C97931D4E86FA48AFC1473053A new file: .vs/CopilotSnapshots/800E39400095584FAD64714B8C7DEAC0/23DA5FED92DF88449BA1921B5E7140E6/96591B376AA2EEF767B776935423B13B new file: .vs/CopilotSnapshots/800E39400095584FAD64714B8C7DEAC0/23DA5FED92DF88449BA1921B5E7140E6/A932F58FF04ACD80FA11101B1306DE89 new file: .vs/CopilotSnapshots/800E39400095584FAD64714B8C7DEAC0/5A35E33E97B9174EA153000C5472DD88/472DB8677F92F1BBFAEE2A938F15234D new file: .vs/CopilotSnapshots/800E39400095584FAD64714B8C7DEAC0/5A35E33E97B9174EA153000C5472DD88/A932F58FF04ACD80FA11101B1306DE89 new file: .vs/CopilotSnapshots/800E39400095584FAD64714B8C7DEAC0/5A35E33E97B9174EA153000C5472DD88/E4F981D6EA2023622C032FCC3DD46755 new file: .vs/CopilotSnapshots/800E39400095584FAD64714B8C7DEAC0/state.mpack new file: .vs/ProjectSettings.json new file: .vs/VSWorkspaceState.json new file: .vs/slnx.sqlite new file: .vscode/c_cpp_properties.json new file: .vscode/launch.json new file: .vscode/settings.json new file: .vscode/tasks.json new file: 1.cpp new file: 2.cpp new file: 3.cpp new file: 3.exe new file: 4.cpp new file: CppProperties.json new file: Untitled-1.cpp new file: a.exe new file: build/Debug/1.o new file: build/Debug/2.o new file: main.cpp new file: math_functions.cpp new file: math_functions.hmain
commit
bd28f1b337
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,55 @@
|
||||
{
|
||||
"Version": 1,
|
||||
"WorkspaceRootPath": "C:\\Users\\Spark\\Desktop\\C demo\\",
|
||||
"Documents": [
|
||||
{
|
||||
"AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|C:\\Users\\Spark\\Desktop\\C demo\\.vscode\\launch.json||{90A6B3A7-C1A3-4009-A288-E2FF89E96FA0}",
|
||||
"RelativeMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|solutionrelative:.vscode\\launch.json||{90A6B3A7-C1A3-4009-A288-E2FF89E96FA0}"
|
||||
},
|
||||
{
|
||||
"AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|C:\\Users\\Spark\\Desktop\\C demo\\main.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
||||
"RelativeMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|solutionrelative:main.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
||||
}
|
||||
],
|
||||
"DocumentGroupContainers": [
|
||||
{
|
||||
"Orientation": 0,
|
||||
"VerticalTabListWidth": 256,
|
||||
"DocumentGroups": [
|
||||
{
|
||||
"DockedWidth": 200,
|
||||
"SelectedChildIndex": 0,
|
||||
"Children": [
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 0,
|
||||
"Title": "launch.json",
|
||||
"DocumentMoniker": "C:\\Users\\Spark\\Desktop\\C demo\\.vscode\\launch.json",
|
||||
"RelativeDocumentMoniker": ".vscode\\launch.json",
|
||||
"ToolTip": "C:\\Users\\Spark\\Desktop\\C demo\\.vscode\\launch.json",
|
||||
"RelativeToolTip": ".vscode\\launch.json",
|
||||
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAgAAAARAAAAAAAAAA==",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.001642|",
|
||||
"WhenOpened": "2026-02-12T04:30:15.516Z",
|
||||
"IsPinned": true,
|
||||
"EditorCaption": ""
|
||||
},
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 1,
|
||||
"Title": "main.cpp",
|
||||
"DocumentMoniker": "C:\\Users\\Spark\\Desktop\\C demo\\main.cpp",
|
||||
"RelativeDocumentMoniker": "main.cpp",
|
||||
"ToolTip": "C:\\Users\\Spark\\Desktop\\C demo\\main.cpp",
|
||||
"RelativeToolTip": "main.cpp",
|
||||
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAsAAAAAAAAAAAAAAA==",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
||||
"WhenOpened": "2026-02-12T04:03:11.156Z",
|
||||
"EditorCaption": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
{
|
||||
"Version": 1,
|
||||
"WorkspaceRootPath": "C:\\Users\\Spark\\Desktop\\C demo\\",
|
||||
"Documents": [
|
||||
{
|
||||
"AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|C:\\Users\\Spark\\Desktop\\C demo\\main.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
||||
"RelativeMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|solutionrelative:main.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
||||
},
|
||||
{
|
||||
"AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|C:\\Users\\Spark\\Desktop\\C demo\\.vscode\\launch.json||{90A6B3A7-C1A3-4009-A288-E2FF89E96FA0}",
|
||||
"RelativeMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|solutionrelative:.vscode\\launch.json||{90A6B3A7-C1A3-4009-A288-E2FF89E96FA0}"
|
||||
}
|
||||
],
|
||||
"DocumentGroupContainers": [
|
||||
{
|
||||
"Orientation": 0,
|
||||
"VerticalTabListWidth": 256,
|
||||
"DocumentGroups": [
|
||||
{
|
||||
"DockedWidth": 200,
|
||||
"SelectedChildIndex": 1,
|
||||
"Children": [
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 1,
|
||||
"Title": "launch.json",
|
||||
"DocumentMoniker": "C:\\Users\\Spark\\Desktop\\C demo\\.vscode\\launch.json",
|
||||
"RelativeDocumentMoniker": ".vscode\\launch.json",
|
||||
"ToolTip": "C:\\Users\\Spark\\Desktop\\C demo\\.vscode\\launch.json",
|
||||
"RelativeToolTip": ".vscode\\launch.json",
|
||||
"ViewState": "AgIAAAAAAAAAAAAAAAAAABAAAAAGAAAAAAAAAA==",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.001642|",
|
||||
"WhenOpened": "2026-02-12T04:30:15.516Z",
|
||||
"IsPinned": true,
|
||||
"EditorCaption": ""
|
||||
},
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 0,
|
||||
"Title": "main.cpp",
|
||||
"DocumentMoniker": "C:\\Users\\Spark\\Desktop\\C demo\\main.cpp",
|
||||
"RelativeDocumentMoniker": "main.cpp",
|
||||
"ToolTip": "C:\\Users\\Spark\\Desktop\\C demo\\main.cpp",
|
||||
"RelativeToolTip": "main.cpp",
|
||||
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAsAAAAAAAAAAAAAAA==",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
||||
"WhenOpened": "2026-02-12T04:03:11.156Z",
|
||||
"EditorCaption": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,24 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "C/C++ Runner: Debug Session",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": true,
|
||||
"cwd": "c:/Users/Spark/Desktop/C demo",
|
||||
"program": "c:/Users/Spark/Desktop/C demo/build/Debug/outDebug",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch main (GDB/LLDB)",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/main",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"preLaunchTask": "build main",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "/usr/bin/gdb"
|
||||
},
|
||||
{
|
||||
"name": "Launch main (Windows)",
|
||||
"type": "cppvsdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/main.exe",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"preLaunchTask": "build main (windows)"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "C/C++ Runner: Debug Session",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": true,
|
||||
"cwd": "c:/Users/Spark/Desktop/C demo",
|
||||
"program": "c:/Users/Spark/Desktop/C demo/build/Debug/outDebug",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int main() {
|
||||
int a = 10;
|
||||
int b = 5;
|
||||
|
||||
cout << "Addition: " << add(a, b) << endl;
|
||||
cout << "Subtraction: " << subtract(a, b) << endl;
|
||||
cout << "Multiplication: " << multiply(a, b) << endl;
|
||||
|
||||
try {
|
||||
cout << "Division: " << divide(a, b) << endl;
|
||||
} catch (const invalid_argument& e) {
|
||||
cerr << "Error: " << e.what() << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "C/C++ Runner: Debug Session",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": true,
|
||||
"cwd": "c:/Users/Spark/Desktop/C demo",
|
||||
"program": "c:/Users/Spark/Desktop/C demo/build/Debug/outDebug",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int main() {
|
||||
int a = 10;
|
||||
int b = 5;
|
||||
|
||||
cout << "Addition: " << add(a, b) << endl;
|
||||
cout << "Subtraction: " << subtract(a, b) << endl;
|
||||
cout << "Multiplication: " << multiply(a, b) << endl;
|
||||
|
||||
try {
|
||||
cout << "Division: " << divide(a, b) << endl;
|
||||
} catch (const invalid_argument& e) {
|
||||
cerr << "Error: " << e.what() << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
{
|
||||
"CurrentProjectSetting": "Mingw64"
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
{
|
||||
"ExpandedNodes": [
|
||||
""
|
||||
],
|
||||
"PreviewInSolutionExplorer": false
|
||||
}
|
||||
Binary file not shown.
@ -0,0 +1,21 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "windows-gcc-x64",
|
||||
"includePath": [
|
||||
"${workspaceFolder}",
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"defines": [
|
||||
"_DEBUG",
|
||||
"UNICODE",
|
||||
"_UNICODE"
|
||||
],
|
||||
"compilerPath": "D:/mingw64/bin/gcc.exe",
|
||||
"intelliSenseMode": "windows-gcc-x64",
|
||||
"cStandard": "c23",
|
||||
"cppStandard": "c++23"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "(gdb) 启动",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${fileDirname}",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "D:/mingw64/bin/gdb.exe",
|
||||
"preLaunchTask": "C/C++: g++.exe 生成活动文件"
|
||||
},
|
||||
{
|
||||
"name": "C/C++ Runner: Debug Session",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": true,
|
||||
"cwd": "c:/Users/Spark/Desktop/C demo",
|
||||
"program": "c:/Users/Spark/Desktop/C demo/build/Debug/outDebug",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "D:/mingw64/bin/gdb.exe",
|
||||
"preLaunchTask": "C/C++: g++.exe 生成活动文件",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
{
|
||||
"C_Cpp_Runner.cCompilerPath": "D:/mingw64/bin/g++.exe",
|
||||
"C_Cpp_Runner.cppCompilerPath": "g++",
|
||||
"C_Cpp_Runner.debuggerPath": "gdb",
|
||||
"C_Cpp_Runner.cStandard": "c23",
|
||||
"C_Cpp_Runner.cppStandard": "c++26",
|
||||
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat",
|
||||
"C_Cpp_Runner.useMsvc": false,
|
||||
"C_Cpp_Runner.warnings": [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Wpedantic",
|
||||
"-Wshadow",
|
||||
"-Wformat=2",
|
||||
"-Wcast-align",
|
||||
"-Wconversion",
|
||||
"-Wsign-conversion",
|
||||
"-Wnull-dereference"
|
||||
],
|
||||
"C_Cpp_Runner.msvcWarnings": [
|
||||
"/W4",
|
||||
"/permissive-",
|
||||
"/w14242",
|
||||
"/w14287",
|
||||
"/w14296",
|
||||
"/w14311",
|
||||
"/w14826",
|
||||
"/w44062",
|
||||
"/w44242",
|
||||
"/w14905",
|
||||
"/w14906",
|
||||
"/w14263",
|
||||
"/w44265",
|
||||
"/w14928"
|
||||
],
|
||||
"C_Cpp_Runner.enableWarnings": true,
|
||||
"C_Cpp_Runner.warningsAsError": false,
|
||||
"C_Cpp_Runner.compilerArgs": [],
|
||||
"C_Cpp_Runner.linkerArgs": [],
|
||||
"C_Cpp_Runner.includePaths": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"C_Cpp_Runner.includeSearch": [
|
||||
"*",
|
||||
"**/*"
|
||||
],
|
||||
"C_Cpp_Runner.excludeSearch": [
|
||||
"**/build",
|
||||
"**/build/**",
|
||||
"**/.*",
|
||||
"**/.*/**",
|
||||
"**/.vscode",
|
||||
"**/.vscode/**"
|
||||
],
|
||||
"C_Cpp_Runner.useAddressSanitizer": false,
|
||||
"C_Cpp_Runner.useUndefinedSanitizer": false,
|
||||
"C_Cpp_Runner.useLeakSanitizer": false,
|
||||
"C_Cpp_Runner.showCompilationTime": false,
|
||||
"C_Cpp_Runner.useLinkTimeOptimization": false,
|
||||
"C_Cpp_Runner.msvcSecureNoWarnings": false,
|
||||
"json.schemaDownload.enable": false,
|
||||
"json.schemaDownload.enableForVsCodeExtensions": false
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
{
|
||||
"tasks": [
|
||||
{
|
||||
"type": "cppbuild",
|
||||
"label": "C/C++: g++.exe 生成活动文件",
|
||||
"command": "D:/mingw64/bin/g++.exe",
|
||||
"args": [
|
||||
"-fdiagnostics-color=always",
|
||||
"-g",
|
||||
"${file}",
|
||||
"-o",
|
||||
"${fileDirname}/${fileBasenameNoExtension}.exe"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "D:/mingw64/bin"
|
||||
},
|
||||
"problemMatcher": [
|
||||
"$gcc"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"detail": "调试器生成的任务。"
|
||||
}
|
||||
],
|
||||
"version": "2.0.0"
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
cout << "hello" << endl;
|
||||
system("pause");
|
||||
return 0;
|
||||
}
|
||||
|
||||
//正常输出 hello world
|
||||
@ -0,0 +1,11 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
cout << "hello1" << endl;
|
||||
system("pause");
|
||||
return 0;
|
||||
}
|
||||
|
||||
//正常输出 hello world
|
||||
@ -0,0 +1,32 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <algorithm> // 包含 std::max_element 和 std::min_element
|
||||
|
||||
|
||||
int main() {
|
||||
std::vector<int> vec = {3, 1, 4, 2, 5};
|
||||
|
||||
// 查找最大值及其索引
|
||||
auto maxIt = std::max_element(vec.begin(), vec.end());
|
||||
int maxValue = *maxIt;
|
||||
int maxIndex = std::distance(vec.begin(), maxIt);
|
||||
|
||||
// 查找最小值及其索引
|
||||
auto minIt = std::min_element(vec.begin(), vec.end());
|
||||
int minValue = *minIt;
|
||||
int minIndex = std::distance(vec.begin(), minIt);
|
||||
|
||||
// 输出向量内容
|
||||
std::cout << "向量: ";
|
||||
for (int num : vec) {
|
||||
std::cout << num << " ";
|
||||
}
|
||||
std::cout << "\n";
|
||||
|
||||
// 输出最大值及其索引
|
||||
std::cout << "最大值: " << maxValue << ",索引: " << maxIndex << "\n";
|
||||
// 输出最小值及其索引
|
||||
std::cout << "最小值: " << minValue << ",索引: " << minIndex << "\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"inheritEnvironments": [
|
||||
"mingw_64"
|
||||
],
|
||||
"name": "Mingw64",
|
||||
"includePath": [
|
||||
"${env.INCLUDE}",
|
||||
"${workspaceRoot}\\**"
|
||||
],
|
||||
"intelliSenseMode": "linux-gcc-x64"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
#include <iostream>
|
||||
include <vector>
|
||||
using namespace std;
|
||||
int main() {
|
||||
vector<int> numbers = {1, 2, 3, 4, 5};
|
||||
cout << "Numbers in the vector: ";
|
||||
for (int num : numbers) {
|
||||
cout << num << " ";
|
||||
}
|
||||
cout << endl;
|
||||
return 0;
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@ -0,0 +1,38 @@
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace std;
|
||||
|
||||
int add(int x, int y) {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
int subtract(int x, int y) {
|
||||
return x - y;
|
||||
}
|
||||
|
||||
int multiply(int x, int y) {
|
||||
return x * y;
|
||||
}
|
||||
|
||||
int divide(int x, int y) {
|
||||
if (y == 0) {
|
||||
throw invalid_argument("Division by zero");
|
||||
}
|
||||
return x / y;
|
||||
}
|
||||
int main() {
|
||||
int a = 10;
|
||||
int b = 5;
|
||||
|
||||
cout << "Addition: " << add(a, b) << endl;
|
||||
cout << "Subtraction: " << subtract(a, b) << endl;
|
||||
cout << "Multiplication: " << multiply(a, b) << endl;
|
||||
|
||||
try {
|
||||
cout << "Division: " << divide(a, b) << endl;
|
||||
} catch (const invalid_argument& e) {
|
||||
cerr << "Error: " << e.what() << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
#include "math_functions.h"
|
||||
|
||||
int add(int a, int b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
int subtract(int a, int b) {
|
||||
return a - b;
|
||||
}
|
||||
|
||||
int multiply(int a, int b) {
|
||||
return a * b;
|
||||
}
|
||||
|
||||
double divide(int a, int b) {
|
||||
if (b == 0) throw std::invalid_argument("division by zero");
|
||||
return static_cast<double>(a) / b;
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
#ifndef MATH_FUNCTIONS_H
|
||||
#define MATH_FUNCTIONS_H
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
int add(int a, int b);
|
||||
int subtract(int a, int b);
|
||||
int multiply(int a, int b);
|
||||
double divide(int a, int b);
|
||||
|
||||
#endif // MATH_FUNCTIONS_H
|
||||
Loading…
Reference in new issue