我想在我的 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/