C++ 使用C++;。“我怎么能?”;";在定制终端?
我有下一个文件序列:C++ 使用C++;。“我怎么能?”;";在定制终端?,c++,macos,terminal,vscode-settings,C++,Macos,Terminal,Vscode Settings,我有下一个文件序列: sample.cpp launch.json c_cpp_properties.json 通过这些配置,我能够在外部终端上按预期运行程序。 在我自定义了终端的外观后出现了问题:当按F5键时,现在显示的是2个终端,在后台显示的是我的自定义终端,它是非活动的,浮动在上面,是原始终端,我可以在其中键入变量并按预期显示结果。 在下一个快照中,您有一个想法: 问题是如何在我的定制终端中直接“cin”和“cout”,禁用原来的黑色终端?诀窍是创建自己的系统()。基本上,它非常简单(e
问题是如何在我的定制终端中直接“cin”和“cout”,禁用原来的黑色终端?诀窍是创建自己的
系统()。基本上,它非常简单(execl(“/bin/sh”、“sh”、“-c”、command、(char*)NULL);
)。我想您可能希望管道连接到您自己的版本,所以请查看execl
和dup
/dup2
,fork
和pipe
调用。作为初学者(您可以看到我使用基本函数编写代码),我在维基百科上查找了这条execl
命令是什么。它似乎是在UNIX系统中实现的,在我们的时代,它在mac os上仍然可以工作。链接位于此处:。但我真的不明白这个指令如何帮助解决我的问题。如何控制线程和进程可以强制VS代码在我的定制终端上打印出来?您可能是初学者,但您想做的事情在标准C++中没有解决方案。这是悲剧,但却是事实。要完成您想要做的事情,您确实需要阅读OS API文档(或者使用一个封装所有这些混乱的库,比如boost
)。我可能会反对这里的共同建议,但我建议您自己尝试使用OS调用来实现这一点,但是请记住,如果您移动到不同的平台,就离开了标准C++域,需要重新实现它。我推荐这个案例,因为这个案例非常适合学习更深层次的东西。好了,我准备好探索这片森林了。但为了做到这一点,我需要一个可靠的领导。教程或类似的东西。问题仍然是:我应该在VisualStudio中用C++编写脚本,它能够使VisualStudio本身改变它的行为吗?如果可能的话,我该怎么开始呢?一些简单的开始。。。例如,以编程方式增加字体大小(修改vs代码设置时这是一项简单的任务)这有多重要?注意看球
#include <iostream>
#include <vector>
using namespace std;
#pragma region - Test Functions
void fn01()
{
int a, b;
cin >> a >> b;
int sum = a + b;
cout << sum << endl;
}
void fn02()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
}
#pragma endregion
int main()
{
cout << "Now the screen will be cleared!" << endl;
//printf("\e[1;1H\e[2J");
system("clear");
cout << "\n==============================";
cout << "Empty Screen" << endl;
fn01();
fn02();
return 0;
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-g",
"${file}",
"-I/Users/Armonicus/MyProjects/C++VSCodeProjects/projects/helloworld01/include",
"-o",
"${fileDirname}/src/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "clang++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/src/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"internalConsoleOptions": "neverOpen",
"externalConsole": true,
"MIMode": "lldb",
"preLaunchTask": "clang++ build active file"
}
]
}
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/include"
],
"defines": [],
"compilerPath": "/usr/bin/clang++",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "macos-gcc-x64"
}
],
"version": 4
}