我正在尝试将来自 microbit 上的加速度计的整数 xyz 组合成一个字符串,然后将其发送到串行端口。我在这里使用带有 microbit DAL 库的在线 mbed 编译器中的 c++。
uBit.init();
uBit.serial.baud(115200);
MicroBitI2C i2c = MicroBitI2C(I2C_SDA0, I2C_SCL0);
MicroBitAccelerometer accelerometer = MicroBitAccelerometer(i2c);
while(1) {
int x=uBit.accelerometer.getX();
int y=uBit.accelerometer.getX();
int z=uBit.accelerometer.getX();
stringstream result;
result << x << "," << y << "," << z;
uBit.serial.send(result.c_str());
uBit.serial.send("\r\n");
}
但是 result.c_str() 给了我一个错误 Error: Class "std::basic_stringstream, std::allocator>" has no member "c_str" in "main.cpp", Line: 26, Col: 34 screenshot