0

I am wanting to generate random data and store it in an hpp file so that I can then include and access it in another file. For Example:

random_data.hpp

uint32_t input[] = { 938, 916, 829, 803, 284, 796, 357}

Now if I include the file random_data.hpp, I can directly use the array "input".

#include "random_data.hpp";
printf(input.size()); //Do somthing

I am trying to generate the hpp file for a object. I was trying to write it by hand in a file but im having trouble on formatting. Is there a better-way to generate it? using std::out?

The object I am tring to currently make is of type Node:

class XY{
public:
    int x;
    int y;
}

Node{
public:
    std::vector< XY > xy;
    std::vector< std::string > name;
}

What is a good way to generate this data/file? And what format would the hpp file be in if manually typed, I have tried:

Node input = { {{1,2},{3,4}}, {'BOB','JOE'} } 
  • Unrelated: It looks like you're trying to learn C++ by trial and error. This is a very, very slow route to competence, let alone mastery. I recommend grabbing [a few good books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) and working your way past simple bugs before you try to write too much more. – user4581301 Mar 13 '20 at 02:11
  • One technique is to use a Singleton (search the internet for "C++ singleton thread safe"). – Thomas Matthews Mar 13 '20 at 03:41
  • Another technique is to declare the variable as global in a cpp file, then make an `extern` declaration in the header file. – Thomas Matthews Mar 13 '20 at 03:43
  • Finally, consider throwing the data into a file. This technique will allow you to change the data without having to recompile your program. – Thomas Matthews Mar 13 '20 at 03:44

0 Answers0