我可以在 C++ 中做这样的事情吗?
//int i,Data[];
//malloc Data[];
$sscanf(line,"Data[%d]=0x%d",i,Data[i]);
Data[] 是一个 int 数组,我正在尝试根据一次性读入的“i”的值来读入随机索引。
最佳答案
你可以这样做:
int index, value;
sscanf(line, "Data[%d]=%d", &index, &value);
// Check if index is within bounds of the array here
Data[index] = value;
您需要“&”,因为 sscanf 将指针作为参数。
关于c++ - C++ 中的 Sscanf(读入值并同时赋值),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7393998/