header-files

How to split this into header and source files?

最后都变了- 提交于 2021-01-28 04:40:16
问题 I have some C code I'd like to split into a header file and a source file: #ifndef BENCHMARK_H #define BENCHMARK_H #ifdef WIN32 #include <windows.h> double get_time() { LARGE_INTEGER t, f; QueryPerformanceCounter(&t); QueryPerformanceFrequency(&f); return (double)t.QuadPart/(double)f.QuadPart; } #else #include <sys/time.h> #include <sys/resource.h> double get_time() { struct timeval t; struct timezone tzp; gettimeofday(&t, &tzp); return t.tv_sec + t.tv_usec*1e-6; } #endif #endif What would be

How do you include a header file that may or may not exist?

偶尔善良 提交于 2021-01-20 04:21:48
问题 Let's assume I define BAR in foo.h. But foo.h might not exist. How do I include it, without the compiler complaining at me? #include "foo.h" #ifndef BAR #define BAR 1 #endif int main() { return BAR; } Therefore, if BAR was defined as 2 in foo.h, then the program would return 2 if foo.h exists and 1 if foo.h does not exist. 回答1: In general, you'll need to do something external to do this - e.g. by doing something like playing around with the search path (as suggested in the comments) and

How do you include a header file that may or may not exist?

元气小坏坏 提交于 2021-01-20 04:13:24
问题 Let's assume I define BAR in foo.h. But foo.h might not exist. How do I include it, without the compiler complaining at me? #include "foo.h" #ifndef BAR #define BAR 1 #endif int main() { return BAR; } Therefore, if BAR was defined as 2 in foo.h, then the program would return 2 if foo.h exists and 1 if foo.h does not exist. 回答1: In general, you'll need to do something external to do this - e.g. by doing something like playing around with the search path (as suggested in the comments) and

How do you include a header file that may or may not exist?

筅森魡賤 提交于 2021-01-20 04:11:39
问题 Let's assume I define BAR in foo.h. But foo.h might not exist. How do I include it, without the compiler complaining at me? #include "foo.h" #ifndef BAR #define BAR 1 #endif int main() { return BAR; } Therefore, if BAR was defined as 2 in foo.h, then the program would return 2 if foo.h exists and 1 if foo.h does not exist. 回答1: In general, you'll need to do something external to do this - e.g. by doing something like playing around with the search path (as suggested in the comments) and

How to fix fatal error: zlib.h: no such file or directory?

牧云@^-^@ 提交于 2020-12-29 08:46:07
问题 I'm trying to compile miniSAT on Kali Linux 64 bits but I keep getting the error message: fatal error: zlib.h: no such file or directory I have read that there might be a linking problem that makes the compiler unable to find the header files, but I'm new to Linux and do not know how to solve that. 回答1: You should install the development support files for zlib, try: sudo apt-get install libz-dev Other package names: zlib1g-dev . If you've already zlib library, make sure you're compiling your

Basic question on c++ header file inclusion?

拈花ヽ惹草 提交于 2020-12-29 06:52:28
问题 What are the differences between below 3 programs ?. Is <iostream> a header file or C++ standard library ? 1. #include<iostream> using namespace std; int main() { return 0; } 2. #include<iostream> int main() { return 0; } 3. #include<iostream.h> int main() { return 0; } Thanks in advance. 回答1: As far as the program that is produced, there is zero difference - since nothing in the iostream library is referenced by the program, none of the library will be compiled in by any intelligent compiler

Basic question on c++ header file inclusion?

浪子不回头ぞ 提交于 2020-12-29 06:50:44
问题 What are the differences between below 3 programs ?. Is <iostream> a header file or C++ standard library ? 1. #include<iostream> using namespace std; int main() { return 0; } 2. #include<iostream> int main() { return 0; } 3. #include<iostream.h> int main() { return 0; } Thanks in advance. 回答1: As far as the program that is produced, there is zero difference - since nothing in the iostream library is referenced by the program, none of the library will be compiled in by any intelligent compiler

Why don't online C++ IDEs support “graphics.h” header file?

我的梦境 提交于 2020-12-06 12:57:51
问题 I tried compiling code using several IDEs of C++ using "graphics.h" header file using the list in TechGeekBuzz: Best C++ Online Compiler but they flag the error 1:21: fatal error: graphics.h: No such file or directory The program I am trying to run is #include<graphics.h> #include <conio.h> int main() { int gd = DETECT, gm; initgraph(&gd,&gm, "C:\\tc\\bgi"); circle(300,300,50); closegraph(); getch(); } 回答1: You should only expect the standard headers to be available in online compilers. Some

Why don't online C++ IDEs support “graphics.h” header file?

懵懂的女人 提交于 2020-12-06 12:57:05
问题 I tried compiling code using several IDEs of C++ using "graphics.h" header file using the list in TechGeekBuzz: Best C++ Online Compiler but they flag the error 1:21: fatal error: graphics.h: No such file or directory The program I am trying to run is #include<graphics.h> #include <conio.h> int main() { int gd = DETECT, gm; initgraph(&gd,&gm, "C:\\tc\\bgi"); circle(300,300,50); closegraph(); getch(); } 回答1: You should only expect the standard headers to be available in online compilers. Some

How to use the <format> header

家住魔仙堡 提交于 2020-11-29 05:09:32
问题 In a related question (" std::string formatting like sprintf ") I learned about this awesome new C++20 header <format>. However, there seems to be no supporting compiler. Is this correct or is there a way to use it anyway? I'm using g++ 9.3 with the -std=c++2a flag and the library <format> is not recognised. #include <format> // fatal error: format: No such file or directory #include <iostream> int main(){ std::cout << std::format("Hello {}!", "World"); } g++-9 test.cpp -o test -std=c++2a 回答1