發在CSDN的帖子,還沒人回覆:(
結構體:
struct myData
{
float startFlow;
float endFlow;
float leakDistance[5];
};
賦值:
myData dataToServer;
dataToServer......
發送:
myClient.sendData((char*)&dataToServer,sizeof(myData))
sendData函數:
int myTcpSocket::sendData(const char* data, int nDataLength)
{
int numBytes; // the number of bytes sent
if(sizeof(data)!=nDataLength) return -1;
// Sends the message to the connected host
try
{
if (numBytes = send(socketId,data,nDataLength,0) == -1)
(下略)
或許if(sizeof(data)!=nDataLength)這樣的比較不對,但問題的關鍵不在這。
通過跟蹤調試,發現sendData函數中的data爲空,也就是說結構體沒有傳進來!
結構體裏的變量是float型的,是不是字節長,然後轉換成char時是0,結果就成了字符串的結尾符號了?難道是這個原因?
我曾試過結構體裏面放兩個char類型的變量,似乎就能正常運轉。
這個轉換難道還挑數據類型?不會吧?
環境:VC6
Someone help me!