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
2 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
need help with coding for unity
General
3
Reddit r/programming
Avro schemas for Kafka developers: the 10-minute practical guide
General
2
Dev.to (EN Zone)
How to name things
General
3
Reddit r/programming
Building an Interactive Excel Dashboard for E-commerce Product Analysis: A Case Study of Jumia.
General
2
Dev.to (EN Zone)
Comments0
No comments yet — be the first