visualstudio2022怎么在新建项中包含头文件

visualstudio2022怎么在新建项中包含头文件,第1张

首先我们先找到Visual Studio编辑器中的“解决方案”,右键点击并在下拉菜单中找到属性并点击。

点击后会出现一个d窗,在里面找到“调试源文件”,在右边列表中找到include文件夹的路径并复制下来。

在文件资源管理器中输入路径找到include文件夹。在include文件夹中新建一个文件夹bits。

在桌面创建一个txt文档,在文档中输入代码,这里提供一个万能头文件的代码和一个线性筛素数函数的代码。

//万能头文件代码 txt文档命名为stdc++

// C

#ifndef _GLIBCXX_NO_ASSERT

#include <cassert>

#endif

#include <cctype>

#include <cerrno>

#include <cfloat>

#include <ciso646>

#include <climits>

#include <clocale>

#include <cmath>

#include <csetjmp>

#include <csignal>

#include <cstdarg>

#include <cstddef>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <ctime>

#if __cplusplus >= 201103L

#include <ccomplex>

#include <cfenv>

#include <cinttypes>

#include <cstdalign>

#include <cstdbool>

#include <cstdint>

#include <ctgmath>

#include <cwchar>

#include <cwctype>

#endif

// C++

#include <algorithm>

#include <bitset>

#include <complex>

#include <deque>

#include <exception>

#include <fstream>

#include <functional>

#include <iomanip>

#include <ios>

#include <iosfwd>

#include <iostream>

#include <istream>

#include <iterator>

#include <limits>

#include <list>

#include <locale>

#include <map>

#include <memory>

#include <new>

#include <numeric>

#include <ostream>

#include <queue>

#include <set>

#include <sstream>

#include <stack>

#include <stdexcept>

#include <streambuf>

#include <string>

#include <typeinfo>

#include <utility>

#include <valarray>

#include <vector>

#if __cplusplus >= 201103L

#include <array>

#include <atomic>

#include <chrono>

#include <condition_variable>

#include <forward_list>

#include <future>

#include <initializer_list>

#include <mutex>

#include <random>

#include <ratio>

#include <regex>

#include <scoped_allocator>

#include <system_error>

#include <thread>

#include <tuple>

#include <typeindex>

#include <type_traits>

#include <unordered_map>

#include <unordered_set>

#endif

//线性素数筛代码

bool vis[100005]

int prime[10005]

int cnt=0

void xianxingshai()

{

for(int i=2i<=100005i++)

{

if(!vis[i]) prime[++cnt]=i

for(int j=1j<=cnt,i*prime[j]<=100005j++)

{

vis[i*prime[j]]=1

if(i%prime[j]==0) break

}

}

}

//插入由此代码组成的头文件后 标识符cnt vis prime 将不可用

//prime[i]可表示第i个素数,直接使用即可

//素数不超过100005

然后将txt文档的后缀名从.txt改为.h,并复制到文件夹bits中(这里会显示需要提供管理员权限,直接点就可以了,不需要管)。

然后这些头文件就可以直接使用啦,使用方法如下所示:

这样制作一个自己的头文件就成功啦。

C++ 标准头文件 为了 和 C 标准头文件区分开,所以不用 后缀名

重新包装了 C标准头文件 为 前面加c ,比如 cstdio 基本就是原来的 stdio.h

cstdio 头文件的内容,包含了 stdio.h ,

但是原来c里面的函数名字先undef,然后重新定义

比如 #undef printf 再using ::printf

C/C++ code

#pragma GCC system_header

#include <bits/c++config.h>

#include <stdio.h>

#ifndef _GLIBCXX_CSTDIO

#define _GLIBCXX_CSTDIO 1

// Get rid of those macros defined in <stdio.h>in lieu of real functions.

#undef clearerr

#undef fclose

#undef feof

#undef ferror

#undef fflush

#undef fgetc

#undef fgetpos

#undef fgets

#undef fopen

#undef fprintf

#undef fputc

#undef fputs

#undef fread

#undef freopen

#undef fscanf

#undef fseek

#undef fsetpos

#undef ftell

#undef fwrite

#undef getc

#undef getchar

#undef gets

#undef perror

#undef printf

#undef putc

#undef putchar

#undef puts

#undef remove

#undef rename

#undef rewind

#undef scanf

#undef setbuf

#undef setvbuf

#undef sprintf

#undef sscanf

#undef tmpfile

#undef tmpnam

#undef ungetc

#undef vfprintf

#undef vprintf

#undef vsprintf

_GLIBCXX_BEGIN_NAMESPACE(std)

using ::FILE

using ::fpos_t

using ::clearerr

using ::fclose

using ::feof

using ::ferror

using ::fflush

using ::fgetc

using ::fgetpos

using ::fgets

using ::fopen

using ::fprintf

using ::fputc

using ::fputs

using ::fread

using ::freopen

using ::fscanf

using ::fseek

using ::fsetpos

using ::ftell

using ::fwrite

using ::getc

using ::getchar

using ::gets

using ::perror

using ::printf

using ::putc

using ::putchar

using ::puts

using ::remove

using ::rename

using ::rewind

using ::scanf

using ::setbuf

using ::setvbuf

using ::sprintf

using ::sscanf

using ::tmpfile

using ::tmpnam

using ::ungetc

using ::vfprintf

using ::vprintf

using ::vsprintf

_GLIBCXX_END_NAMESPACE

#if _GLIBCXX_USE_C99

#undef snprintf

#undef vfscanf

#undef vscanf

#undef vsnprintf

#undef vsscanf

_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)

#if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC

extern "C" int

(snprintf)(char * __restrict, std::size_t, const char * __restrict, ...)

throw ()

extern "C" int

(vfscanf)(FILE * __restrict, const char * __restrict, __gnuc_va_list)

extern "C" int (vscanf)(const char * __restrict, __gnuc_va_list)

extern "C" int

(vsnprintf)(char * __restrict, std::size_t, const char * __restrict,

__gnuc_va_list) throw ()

extern "C" int

(vsscanf)(const char * __restrict, const char * __restrict, __gnuc_va_list)

throw ()

#endif

#if !_GLIBCXX_USE_C99_DYNAMIC

using ::snprintf

using ::vfscanf

using ::vscanf

using ::vsnprintf

using ::vsscanf

#endif

_GLIBCXX_END_NAMESPACE

_GLIBCXX_BEGIN_NAMESPACE(std)

using ::__gnu_cxx::snprintf

using ::__gnu_cxx::vfscanf

using ::__gnu_cxx::vscanf

using ::__gnu_cxx::vsnprintf

using ::__gnu_cxx::vsscanf

_GLIBCXX_END_NAMESPACE

#endif // _GLIBCXX_USE_C99

#endif


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11609977.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存