General
No one asked, but I've written a C++ header-only library so you don't have to declare the variable again.
Nguyen Duc Minh Quan DEV Community
20 views
In my spare time, I wrote a header-only C++ library that will help you extract variable declarations from the main(...) function of one .cpp file to the main(...) function of another .cpp file.
Yes, I mean you can declare any type of variable in any way you can think of, as long as it's within the main(...) function, from a custom-named struct to strange declarations like int a,b,c = 100; as long as it's syntax-correct in C++.
Quick Example :
#include<iostream>
#include<vector>
#include "var_saver.hpp"
int main(){
int a = 0;
std::vector<int>c;
double f,r=3,h;
//Save variables to a file
VarSaver::SaveVarToFile(__FILE__,"save.out");//or another name
// Load the variables into target file
VarSaver::LoadVarToFile("save.out","main2.cpp");
return 0;
}
main2.cpp before loading the variables:
#include<iostream>
#include<vector>
int main(){
return 0;
}
main2.cpp after loading the variables:
#include<iostream>
#include<vector>
int main(){
int a=0;
std::vector<int>c;
double f;
double r=3;
double h;
return 0;
}
Key advantage : You only need to call the function once—anywhere in your code, as long as it gets executed at least once during runtime.
Anyway, you can visit, check out, and try out this library.
Note: If you can't read the code in the repository, it's my fault, not yours. I'm a competitive programmer, so you might have some difficulty reading variable names and trying to understand their meaning.
Link repository: VarSaver
I'd love to hear your feedback and suggestions!
Read original: https://dev.to/meolaptrinh/no-one-asked-but-ive-written-a-c-header-only-library-so-you-dont-have-to-declare-the-variable-20ia
← Previous
Global warming will exceed 1.5-degree limit, UN says
Next →
Streaming Native Speech-to-Text for Embedded Web Use
Related
Semantic tag vs Non-Semantic tag
General
51
Dev.to (EN Zone)
How LinkedIn "Bold" Text Actually Works (It's Not Bold At All)
General
43
Dev.to (EN Zone)
Google ADK Callbacks Are a Policy Plane, Not Just Hooks
General
44
DEV Community 周榜
How I Modelled My Power BI Data — Data Modelling, Relationships & Joins (Kenya Crops Dataset)
General
41
DEV Community 周榜
Comments0
No comments yet — be the first