I have the following:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <string>
struct headerStruct{
uint8_t header;
uint8_t data_1;
uint8_t data_2;
uint8_t data_3;
uint8_t data_4;
} my_header_0;
struct headerStruct2{
uint8_t data_8;
uint8_t data_9;
} my_header_1;
int main(void)
{
std::stringstream ss;
for(int i=0; i < 2; i++)
{
ss.str("");
ss << "my_header_" << i;
std::cout << "size of struct: " << sizeof(ss) << std::endl; // I know this line will be wrong but you get what I want to do, I want the size to output 5 and 2 for this example
}
}
there will be times that i would want to iterate the number of headers i have, i.e my_header_0, my_header_1, ... my_header_n. Which is why i tried placing it in the stringstream ss so i could just edit the string and call the sizeof function. There will be times that I will have more version of my_header_n, n being any number each with a different size. However, I am not sure on how to implement this already.
The output of the sample code above is:
size of struct: 248
size of struct: 248
I understand that 248 is the size of the ss object itself.
However, I want my output to be
size of struct: 5
size of struct: 2
which is actually the size of the structs listed above.
Is this possible? Or any recommended ways to have the expected output.