quick #define question and an other one about data export

1)
I'm having a peculiar problem and I'm not sure how to fix it. Let say I have a couples of #define something 85,etc. All those defines were use for a first.cpp but were transported to a .h and said .h was included into a second.cpp (so first.cpp's function are accessed trough #define "first.h" in the second.cpp)

Is there a way to transfer the #defines and put them directly a top second.cpp? Right now they are somewhat buried into the .h and making it quite problematic to change program parameter without having to switch opening all the .h

2) Is there an easy way to record integer to be exported in an other file like a .dat to be read by excel or something similar?
Last edited on
1) Instead of putting the constants to first.h put them into a separate header that can be included without first

2) You can do that with fstream http://www.cplusplus.com/reference/iostream/fstream/

One suggestion: don't use #define instead use const int or const double or alike for constants (if it's C++ of course). That helps to avoid/detect name clash
1) That doesn't seem to be working and gives me multiple "was not declared in this scope" errors. I use defines because its kinda of a requirement of the work.(given to me by a teacher)
Since I don't see your code I can only give vague suggestions...
That is an excellent point, alright.


module1.cpp
1
2
#include"module_o.h"
#include <WinConsole.h>  


module1.h
1
2
3
4
5
6
7
8
9
10
11
#ifndef module_ocean
#define module_o


#include <stdio.h>      
#include <stdlib.h>     
#include <ctime>        


#define H  20
#define L  80 


main.cpp
 
#include "module_o.h" 



like here, I would hope that the H and L are transferable directly in the main.cpp to give something that look like
1
2
3
#include "module_o.h"
#define H  20
#define L  80 


P.s I'm also unable to transfer that WinConsole to my .h either...odd. (I'm using dev-c++)
Last edited on
This
1
2
#ifndef module_ocean
#define module_o 
doesn't match. So that guard is useless. And don't forget the #endif!


if you mean #include with transfer. So yes, you should be able to #include anything anywhere.

the effect of #define H 20 is that any 'H' used after the #define (no matter if it is WinConsole.h or somewhere else) will be replaced by 20.

1
2
3
4
#define H  20
...

int H = 30; // Compiler error! 


So your problems may have multiple reasons

EDIT: Oh and dev-c++ is outdated. Better use a newer ide (like code::blocks)
Last edited on
Thx a lot for the hand coder777
Topic archived. No new replies allowed.