https://www.youtube.com/watch?v=UqCZda8DLGc
main.cpp
/*
홍정모 연구소 https://honglab.co.kr/
*/
#include <iostream> // iostream이라는 헤더를 포함(include)
using namespace std; // 네임스페이스 설명 std::cout
int main() // entry point
{
// 주석(comment) 다는 방법
cout << "Hello, World!" << endl;
// printf("Hello World!!! by printf");
return 0;
}
C/C++ Edit Configuration 설정--------------------
Ctrl+Shift+P
c++ edit con 입력하면
C/C++: Edit Configurations (UI)
Compiler path 설정 C:/mingw64/bin/g++.exe
IntelliSense mode 설정 windows-gcc-x64
c_cpp_properties.json - 기본적설정 담겨있음
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:/mingw64/bin/g++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
main.cpp - Run - Run Without Debugging - Ctrl+F5 ← 이걸로 실행하면 됨
C++ (GBD/LLDB) 선택
C/C++: g++.exe build and debug action file preLaunchTask: C/C++: g++.exe build active file 선택
[Browse for CMamkeLists.txt] Search for CMakeLists.txt on this computer - esc로 무시하면 됨
터미널 클릭하면 실형결과 나와있음
팁) 터미널 제목 오른쪽에서 오른마우스 Ranel Position - Right 출력화면 보기 편함
tasks.json - Ctrl+F5 누를때 설정 담겨있음
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe 활성 파일 빌드",
"command": "C:/mingw64/bin/g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:/mingw64/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "디버거에서 생성된 작업입니다."
}
],
"version": "2.0.0"
}
디버깅 설정--------------------
Ctrl+Shift+P
c++ de 입력
C/C++: Add Debug Configuration 디버거 설정
C/C++: g++.exe Build and debug active file prelaunchTask: C/C++: g++.exe build active file 선택
launch.json 생성됨 - 디버거 설정 담겨있음
{
"configurations": [
{
"name": "C/C++: g++.exe 활성 파일 빌드 및 디버그",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "C:/mingw64/bin",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "gdb에 자동 서식 지정 사용",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "디스어셈블리 버전을 Intel(으)로 설정",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe 활성 파일 빌드"
}
],
"version": "2.0.0"
}
==================== 참고만 하세요
이번에는 vscode를 통하지 않고
직접 gcc를 실행 시키기
g++ c:\Users\notebook\clang\HongLabCppSummary\Ex01_HelloWorld\main.cpp -o HelloWorld.exe
그러면 HelloWorld.exe가 만들어짐
터미널 화면 지우기 cls
HelloWorld.exe
실행됨
====================
윈도우 한글 입출력 설정
main.cpp
/*
홍정모 연구소 https://honglab.co.kr/
*/
#include <iostream> // iostream이라는 헤더를 포함(include)
using namespace std; // 네임스페이스 설명 std::cout
int main() // entry point
{
// 주석(comment) 다는 방법
cout << "Hello, World!" << endl;
// printf("Hello World!!! by printf");
// 입출력에 대해서는 뒤에 다시 나와요.
char user_input[100]; // 문자열 배열
cin >> user_input;
cout << user_input;
return 0;
}
vscode에서 visual studio의 컴파일러를 사용하는 방법--------------------
vscode 닫기
visual studio 설치
https://www.youtube.com/watch?v=P9JB-4hw0KY
visual studio 2022 다운로드
https://visualstudio.microsoft.com/ko/vs/community/
Visual Studio 2022 커뮤니티 버전 – 최신 무료 버전 다운로드
Windows, Android 및 iOS용 최신 개발자 앱을 만들기 위한 모든 기능을 갖춘 확장 가능한 무료 IDE를 사용해 보세요. 지금 무료로 커뮤니티를 다운로드하세요.
visualstudio.microsoft.com
Visual Studio Installer
C++를 사용한 데스크톱 개발 - 체크해서 추가하기 ( Desktop development with C++ )
설치후
windows 버튼
x64 Native Tools Command Prompt for VS 2022 Preview 실행
중요 안하면 에러남
예제 코드가 있는 위치로 이동
C:\Users\notebook\clang\HongLabCppSummary>
code . 실행
.vscode 안에 있는 내용 모두 지우고
Ctrl+Shift+p
C/C++ Edit Comfiguration (UI) 선택
Compiler path - cl.exe 설정
닫기
c_cpp_properties.json 생성됨
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.22621.0",
"compilerPath": "cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
상단메뉴-실행 선택 ------------------------------안해서 에러 x64 Native Tools Command Prompt for VS 2022 Preview
c++ (windows) 선택 ------------------------------ 안해서 에러 x64 Native Tools Command Prompt for VS 2022 Preview
C/C++: cl.exe build and debug active file preLaunchTask: C/C++: cl.exe build active file Detected Task (compiler: cl.exe) 선택 ------------------------------ 안해서 에러 x64 Native Tools Command Prompt for VS 2022 Preview
No CMakeLists.txt was found. 무시하고 esc로 빠져나오기 ------------------------------ 안해서 에러 x64 Native Tools Command Prompt for VS 2022 Preview
차선책
디버깅 설정--------------------위 부분 에러로 안나와서 디버깅 설정으로 대체
Ctrl+Shift+P
c++ de 입력
C/C++: Add Debug Configuration 디버거 설정
C/C++: cl.exe 활성 파일 빌드 및 디버그 preLaunchTask: C/C++: cl.exe 활성 파일 빌드
launch.json
{
"configurations": [
{
"name": "C/C++: cl.exe 활성 파일 빌드 및 디버그",
"type": "cppvsdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "C/C++: cl.exe 활성 파일 빌드"
}
],
"version": "2.0.0"
}
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: cl.exe 활성 파일 빌드",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/nologo",
"/Fe${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$msCompile"
],
"group": "build",
"detail": "디버거에서 생성된 작업입니다."
}
],
"version": "2.0.0"
}
Ctrl+F5 실행
한글도 입력 받아 출력이 됨
참고 cout << "한글"
https://blog.naver.com/wlvkddlwkd/222312283109
[C/C++] VS Code 한글 깨짐 현상
Visual Studio Code 한글창 깨짐 현상 해결 방법 출력 환경에 따라 해결 방법이 다름 cmd창 한글 깨짐 ...
blog.naver.com
VS Code 하단에 설정 클릭(보통 UTF-8)
Save with Encoding : 설정 저장
korean EUC-KR
다시 빌드(Ctrl + Shift + B)하고 실행(F5)
생성하는 모든 파일에 적용
1. 톱니바퀴 클릭 - 설정
* 키보드 Ctrl + ,
encoding 입력 - Auto Guess Encoding 체크 - Encoding을 Korean (EUC-KR)로 변경
'컴퓨터 > vscode' 카테고리의 다른 글
vscode editor 자체 글씨 크기 확대 축소 (0) | 2025.02.22 |
---|---|
vscode extensions (0) | 2023.01.14 |
vscode 터미널 지우기 cls (0) | 2022.09.01 |
vscode python debug 중단점 작동 안함 (0) | 2022.05.25 |
vscode 디버깅 (0) | 2022.05.17 |