C++如何正确使用#include?

标签 c++ header active-directory include

我想在我的 main.cpp 程序中包含 printstuff.h。我得到没有这样的文件或目录错误。我不想把整个目录都用双引号引起来。我只想简单地把 printstuff.h 我如何完成这个?

我正在使用 Visual Studio 2012。

主要.cpp

#include<iostream>
#include<cstdlib>
#include<printstuff.h>
using namespace std;

inline void swap( int *x, int *y ) {
    int *z = x;
    *x = *y;
    *y = *z;
}

int main( ) {
    /*int x = 0, y = 1;
    swap( x, y );
    cout << x << endl << y << endl;*/

    printStuff( );

    system( "pause" );

    return 0;
}

打印 Material .h

#include<iostream>
using namespace std;

void printStuff( );

void printStuff( ) {
    int count[ ] = { 1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 };
    char symb[ ] = "abcdefghijk";

    for ( int j = 1; j < 12; j++ ) {
        char c = symb[ j ];

        for ( int i = 0; i < 11; i++ ) {
            int times = count[ i ];

            while ( times != 0 ) {
                cout << c;
                times--;
            }

            cout << endl;
        }
    }
}

最佳答案

在项目的属性页中,将“printstuff.h”的路径放在“其他包含目录”中。通过这样做,您可以通过 #include <printstuff.h> 使用头文件。

所以,假设“some.h”文件路径在“C:\ref\include”中,而您的项目路径在“C:\Projects”中。

  • 如果你把'C:\ref\include'的路径放在'Additional Include Directories'中,你可以使用#include <some.h> .
  • 如果不输入路径,则必须使用相对路径,如#include "..\ref\include\some.h" .

关于C++如何正确使用#include?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21407654/

相关文章:

c++ - 无法弄清楚为什么头文件中的私有(private)成员在 cpp 文件中不起作用

c++ - C++ 头文件的正确布局

asp.net - 客户可配置的 ASP.NET 网站安全性,用于对页面和按钮访问进行细粒度控制

c# - 在 LINQ To ActiveDirecory 中检测到 DisconnectedContext

c++ - 我们是否需要将 volatile 关键字和互斥锁一起用于线程安全?

c++ - WinSock2:使用 recv 和 send 在单独的线程中处理接受的传入连接

C 和全局变量/函数

C++ 新手 : Passing an fstream to a function to read data

c++ - 从 .net 调用带有 STL 容器的 c++ dll

asp.net - 尝试通过ASP.NET更改AD中的密码 "user must change"