본문 바로가기

모각독 Study/4기

C++ 프로그래밍 0. 시작

#네임스페이스를 사용하지 않을 경우

#include <iostream>
#: 전처리기로, 컴파일 시작시 우선적으로 처리
iostream: 표준 입출력을 다루는데 필요한 기능을 포함하는 라이브러리를 프로그램에 포함시킴.
          키보드에서 입력받거나 화면에 출력하는데 사용

int main() {
	std::cout << "가나다" << std::endl; //화면에 텍스트를 출력
    return 0;
}

 

#네임스페이스를 사용할 경우

#include <iostream>
#: 전처리기로, 컴파일 시작시 우선적으로 처리
iostream: 표준 입출력을 다루는데 필요한 기능을 포함하는 라이브러리를 프로그램에 포함시킴.
          키보드에서 입력받거나 화면에 출력하는데 사용

using namespace std;
using namespace: 표준 네임스페이스를 사용하겠다는 의미
namespace: 변수 이름이나 함수 이름과 같이 명칭을 사용하는 공간으로 소속을 나타냄

int main() {
	cout << "가나다" << endl; //화면에 텍스트를 출력
    return 0;
}

 

 

#실행을 하려면....????? + 에러

빌드 - 솔루션 빌드

 

이후 디버그 - 디버깅 시작/디버그하지 않고 시작

 

 

시작하면 실행되어야하는데 에러가 남

 

다시 빌드해봄

ㅡㅡ안됨

 


 

#VSCODE C/C++세팅하기

 

 

VSCODE Community 2022버리고 VSCODE로 진행하기로 함

근데 Extensiong문제로 확장팩이 검색이 안되어서 VSCODE MarketPlace에서 수동설치하기로 함

 

https://marketplace.visualstudio.com/search?term=c%2Fc%2B%2B&target=VSCode&category=All%20categories&sortBy=Relevance 

 

Search results for "c/c++", Visual Studio Code on Visual Studio Marketplace

 

marketplace.visualstudio.com

 

검색 후 들어가서 우측 하단의 Download Extension에서 VSIX파일 다운받으면 됨

 

 

 

 

1) C/C++ 설치

 

 

 

 

그다음 VSCODE로 넘어와서 Extension ... 를 누른 뒤 Install from VSIX클릭

 

아까 다운받은 파일을 선택한다

 

완료!

 

잘 설치되었나 확인하기위해 좌측하단 톱니바퀴 -> Extension들어가면

 

잘 설치되어 있음!

 


 

 

 

2-1) C++ Helper or  C-mantic 설치

함수 프로토타입 정의 자동으로 해준다는데 둘 중 하나만 받으면 될 듯?

 

 

 

3) MinGW 설치

https://sourceforge.net/projects/mingw-w64/files/

 

MinGW-w64 - for 32 and 64 bit Windows - Browse Files at SourceForge.net

Trusted Business Password Manager Dashlane fills all your passwords, payments, and personal details wherever you need them, across the web, on any device.

sourceforge.net

여기서 다운받을 수 있는데

 

 

 

 

 

 

https://rasino.tistory.com/307

 

【 C 환경설정 】 VS code에서 C/C++ 코딩환경 구축하기

【 C 환경설정 】 VS code에서 C/C++ 코딩 환경 구축하기 요즘 파이썬(python)이나 자바(JAVA), javascript C# 등등 하이레벨 언어를 학습하던 사람들이 프로그래밍의 근간을 튼튼히 한다거나? 여러 가지 이

rasino.tistory.com

이걸 보고 잘 따라해보기

 

 

 

mingw-get-setup.exe
0.08MB

 

 

위 링크에서 주운 파일로 설치 시작

 

 

 

install 클릭

 

 

 

 

Continue 클릭

 

 

 

Continue 클릭

 

 

이런식으로 체크박스 - Mark for Installation 누르면 체크 됨

 

 

4개 체크 후

 

 

Apply Changes 클릭

 

 

 

Apply 클릭하고 계속 기다리면 됨

 

 

 

Close 뜨면 닫고 환경설정하러 가기


#환경설정

 

 

 

내컴퓨터 - 우클릭 - 속성 - 고급 시스템 설정 - 고급탭 - 환경변수

 

아래쪽에서 Path - 편집

새로만들기 - C:\MinGW\bin

 

 

 

설치 확인을 위해 window버튼 + r - cmd입력해서 명령프롬프트 창 켜주기

 

gcc -v 를 입력했을 때 마지막에 버전이 나오면 끝

 

 


 

#VSCODE에서 설정하기

Terminal - Configure Default Build Task...클릭

 

이걸 클릭하면 

 

 

 

 

3) setting.json 설정

톱니바퀴 - settings

 

Open Settings(JSON)클릭

 

 

"C_Cpp.default.compilerPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30037\\bin\\Hostx64\\x64\\cl.exe"

저장해준다

 


#다시 실행해보기

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: cl.exe build active file",
            "command": "cl.exe",
            "args": [
                "/Zi",
                "/EHsc",
                "/nologo",
                "/Fe${fileDirname}\\${fileBasenameNoExtension}.exe",
                "${file}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$msCompile"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

뭔가 만들어짐

 

 

이제 이 내용을

https://rasino.tistory.com/307

 

【 C 환경설정 】 VS code에서 C/C++ 코딩환경 구축하기

【 C 환경설정 】 VS code에서 C/C++ 코딩 환경 구축하기 요즘 파이썬(python)이나 자바(JAVA), javascript C# 등등 하이레벨 언어를 학습하던 사람들이 프로그래밍의 근간을 튼튼히 한다거나? 여러 가지 이

rasino.tistory.com

여기 있는 tasks.json을 다운받은 뒤 복붙하면 됨

{
    "version": "2.0.0",
    "runner": "terminal",
    "type": "shell",
    "echoCommand": true,
    "presentation": {
        "reveal": "always"
    },
    "tasks": [
        {
            "label": "save and compile for C++",
            "command": "g++",
            "args": [
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "group": "build",
            "problemMatcher": {
                "fileLocation": [
                    "relative",
                    "${workspaceRoot}"
                ],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        },
        {
            "label": "save and compile for C",
            "command": "gcc",
            "args": [
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "group": "build",
            "problemMatcher": {
                "fileLocation": [
                    "relative",
                    "${workspaceRoot}"
                ],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        },
        {
            "label": "execute",
            "command": "cmd",
            "group": "test",
            "args": [
                "/C",
                "${fileDirname}\\${fileBasenameNoExtension}"
            ]
        },
        {
            "type": "cppbuild",
            "label": "C/C++: gcc.exe 활성 파일 빌드",
            "command": "C:\\MinGW\\bin\\gcc.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "디버거에서 생성된 작업입니다."
        },
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe 활성 파일 빌드",
            "command": "C:\\MinGW\\bin\\g++.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
//            "group": {
//               "kind": "build",
//                "isDefault": true
//            },
            
            "detail": "디버거에서 생성된 작업입니다."
        },
        {
            "type": "cppbuild",
            "label": "C/C++: gcc.exe 활성 파일 빌드",
            "command": "C:\\MinGW\\bin\\gcc.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
              
            // "group": {
            //     "kind": "build",
            //     "isDefault": true
            // },

            "detail": "컴파일러: C:\\MinGW\\bin\\gcc.exe"
        }
    ]
}

 

 

나머지 단축키 세팅은 저 링크보고 하고싶으면 하고 아니면 말면 될듯

 

 

 

 

 

 

 


#VS Code - aleady running as asministrator 에러가 난다면

C:\Users\MINE(사용자이름)\AppData\Local\Programs\Microsoft VS Code

해당 경로에 들어가서 우클릭 - 호환성 - 관리자모드 실행 체크

 

 

 

 

 

 

개열받네 삭제하고 다시 처음부터 해봐여ㅑ지 ㅡㅡ

'모각독 Study > 4기' 카테고리의 다른 글

자료구조 - 1. 자료구조란, 2. 배열  (0) 2023.09.10