首页 > 解决方案 > 编译时不包含所有头文件并提供输出

问题描述

我一直在尝试使用 Visual Studio 来运行我的 C++ 代码,但我找不到解决方法。我遇到了这个名为C/C++ Compile Run的扩展,它使用起来很简单。我还使用标准的C/C++ Microsoft Extension

然后我通过运行以下代码进行了尝试:

#include<iostream>
using namespace std;
int main(){
    cout<<"hello";
    char x[10];
    cout<<"\nEnter a string please: ";
    gets(x);
    puts(x);
}

我忘了包括stdio.h,但使用 C/C++ 编译运行扩展成功编译的代码。它给出了这个输出:

hello
Enter a string please: string
string

但是,我没有包括stdio.h. 有没有什么办法解决这一问题?或者我应该尝试另一种编译 C++ 代码的方法?

标签: c++visual-studio-codecompilation

解决方案


推荐阅读