VSCode
the source code is a simple cpp file that only involves standard library import.
compiles and runs with the exception of an error warning, as shown in the following figure.
267272320315313343267250.cpp is not my file, so how did this come from? Why open this file? Did the compiler run still pass?
the question is a rookie. I don"t know what to look for. Thank you
:
launch.json is as follows:
// https://github.com/Microsoft/vscode-cpptools/blob/master/launch.md
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch", //
"type": "cppdbg", // cppdbg
"request": "launch", // launchattach
"program": "${fileDirname}/${fileBasenameNoExtension}.exe", //
"args": [], //
"stopAtEntry": false, // truetrue
"cwd": "${workspaceFolder}", //
"environment": [], //
"externalConsole": true, // true
"internalConsoleOptions": "neverOpen", // neverOpen"" gdb
"MIMode": "gdb", // gdblldblldbwindows
"miDebuggerPath": "gdb.exe", //
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "Compile" // tasks.jsonlabel
}
]
}
task.json file is as follows:
{
"version": "2.0.0",
"tasks": [
{
"label": "Compile",
"command": "gPP",
"args": [
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe",
"-g",
"-Wall",
"-static-libgcc",
"-std=cPP11"
],
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"problemMatcher":"$gcc"
}
]
}
setting file is as follows:
"files.defaultLanguage": "cpp",
"code-runner.runInTerminal": true,
"code-runner.executorMap": {
"c": "cd $dir && clang $fileName -o $fileNameWithoutExt.exe -Wall -g -Og -static-libgcc -fcolor-diagnostics --target=x86_64-w64-mingw -std=c11 && $dir$fileNameWithoutExt",
"cpp": "cd $dir && clangPP $fileName -o $fileNameWithoutExt.exe -Wall -g -Og -static-libgcc -fcolor-diagnostics --target=x86_64-w64-mingw -std=cPP17 && $dir$fileNameWithoutExt"
},
"code-runner.preserveFocus": true,
"code-runner.clearPreviousOutput": false,
"C_Cpp.clang_format_sortIncludes": true,
"C_Cpp.intelliSenseEngine": "Default",
"C_Cpp.errorSquiggles": "Disabled",
"editor.formatOnType": true,
"editor.snippetSuggestions": "top",
"clang.cflags": [
"--target=x86_64-w64-mingw",
"-std=c11",
"-Wall"
],
"clang.cxxflags": [
"--target=x86_64-w64-mingw",
"-std=cPP17",
"-Wall"
],
"clang.completion.enable":false ,
c_cpp_properties.json is as follows:
{
"configurations": [
{
"name": "Win32",
"intelliSenseMode": "clang-x64",
"includePath": [
"${workspaceFolder}",
"C:/Program Files/LLVM/lib/gcc/x86_64-w64-mingw32/7.2.0/include/cPP",
"C:/Program Files/LLVM/lib/gcc/x86_64-w64-mingw32/7.2.0/include/cPP/x86_64-w64-mingw32",
"C:/Program Files/LLVM/lib/gcc/x86_64-w64-mingw32/7.2.0/include/cPP/backward",
"C:/Program Files/LLVM/lib/gcc/x86_64-w64-mingw32/7.2.0/include",
"C:/Program Files/LLVM/include",
"C:/Program Files/LLVM/x86_64-w64-mingw32/include",
"C:/Program Files/LLVM/lib/gcc/x86_64-w64-mingw32/7.2.0/include-fixed"
],
"defines": [
"_DEBUG",
"UNICODE",
"__GNUC__=7",
"__cdecl=__attribute__((__cdecl__))"
],
"browse": {
"path": [
"${workspaceFolder}",
"C:/Program Files/LLVM/lib/gcc/x86_64-w64-mingw32/7.2.0/include/cPP",
"C:/Program Files/LLVM/lib/gcc/x86_64-w64-mingw32/7.2.0/include/cPP/x86_64-w64-mingw32",
"C:/Program Files/LLVM/lib/gcc/x86_64-w64-mingw32/7.2.0/include/cPP/backward",
"C:/Program Files/LLVM/lib/gcc/x86_64-w64-mingw32/7.2.0/include",
"C:/Program Files/LLVM/include",
"C:/Program Files/LLVM/x86_64-w64-mingw32/include",
"C:/Program Files/LLVM/lib/gcc/x86_64-w64-mingw32/7.2.0/include-fixed"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"cStandard": "c11",
"cppStandard": "cPP11"
}
],
"version": 3
}
Source code:
-sharpinclude <algorithm>
-sharpinclude <iostream>
-sharpinclude <list>
-sharpinclude <string>
-sharpinclude <vector>
void elim_dups(std::vector<std::string> &words)
{
std::sort(words.begin(), words.end());
std::vector<std::string>::iterator end_of_unique = std::unique(words.begin(), words.end());
words.erase(end_of_unique, words.end());
}
bool is_shorter(const std::string &sa, const std::string &sb)
{
return sa.size() < sb.size();
}
void elim_dups_stable(std::vector<std::string> &words)
{
elim_dups(words);
std::stable_sort(words.begin(), words.end(), is_shorter);
}
//lambda
void elim_dups_stable_lambda(std::vector<std::string> &words)
{
elim_dups(words);
std::stable_sort(words.begin(), words.end(),
//lambda ->bool,
[](const std::string &sa, const std::string &sb) -> bool { return sa.size() < sb.size(); });
}
int main()
{
std::vector<int> intab{1, 2, 3, 4, 5, 6};
std::vector<std::string> str{"ab", "ac", "abc", "cb", "ca", "cba", "cbb", "ca", "cbc", "cc"};
elim_dups(str);
for (auto var : str)
{
std::cout << var << " ";
}
std::cout << std::endl;
elim_dups_stable_lambda(str);
for (auto var : str)
{
std::cout << var << " ";
}
return 0;
}