我想包括班级,但这没有工作

发布于 2025-01-18 12:32:33 字数 902 浏览 3 评论 0原文

我刚刚学习C++。我正在关注 YouTube 视频,但我陷入了这个阶段。下面是我的文件。

// main.cpp

#include <iostream>
#include "Person.h"

int main()
{
    Person foo;
    foo.set_age(25);

    std::cout << foo.get_age() << std::endl;

    return 0;
}
// Person.h

#ifndef PERSON_H
#define PERSON_H

#pragma once

class Person
{
public:
    void set_age(int a);
    int get_age();

private:
    int age;
};

#endif
// Person.cpp

#include "Person.h"

void Person::set_age(int a)
{
    age = a;
}
int Person::get_age()
{
    return age;
}

我刚刚在vscode中搭建了开发环境并安装了code runner。

每当我单击此处的“运行”按钮时

,它都会显示

启动:程序'.....main.exe'不存在

是否有像php Composer这样的工具可以自动管理它?

将 .cpp 文件的内容移至 .h 文件。

效果很好。但我想把这两个文件分开管理。

I'm just learning C++. I'm following a YouTube video, but I'm stuck at this stage. Below is my files.

// main.cpp

#include <iostream>
#include "Person.h"

int main()
{
    Person foo;
    foo.set_age(25);

    std::cout << foo.get_age() << std::endl;

    return 0;
}
// Person.h

#ifndef PERSON_H
#define PERSON_H

#pragma once

class Person
{
public:
    void set_age(int a);
    int get_age();

private:
    int age;
};

#endif
// Person.cpp

#include "Person.h"

void Person::set_age(int a)
{
    age = a;
}
int Person::get_age()
{
    return age;
}

I just set up the development environment in vscode and installed code runner.

Whenever I click the Run button here

It says

launch: program '.....main.exe' does not exist

Is there a tool like php composer that automatically manages it?

Moved the contents of the .cpp file to the .h file.

It worked fine. But I would like to separate the two files for management.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文