0

こんにちは、私はプログラミングが初めてです。各反復で動的に値を取得する構造体型のポインターを出力し、各反復で防御された構造体メンバーも出力する必要があるパラダイムがあります。

struct my_struct
{
int x;
int y;
}
void function(){

my_struct* a=value.get() // some values will be assigned dynamically to this pointer from other part of function.

my_struct* data = new thread_data;
data->x=1 //which will get updated according the iterations and conditions
data->y=2 //which will get updated according the iterations and conditions

}

ここで、呼び出し元関数で a、x、y の値を出力する必要があります。これらの値を出力する方法。いくつかのような

printf("a=%lx x=%i y=%i\n", a,x,y);

誰かが私にいくつかのアイデアや進め方を教えてもらえますか? どうもありがとう

4

1 に答える 1

2

C++ では、以下を使用できますstd::cout

std::cout << "a=" << a << " x=" << a->x << " y=" << a->y << "\n";

それ以外の場合、printfバージョンは次のように修正される可能性があります。

printf("a=%p x=%i y=%i\n",  a, a->x, a->y);
于 2013-03-19T13:40:43.863 に答える