I'm looking for some help piping a file (16-bit signed little endian integers raw data) from the command line to my program:
cat data.dat | myprogram
Then it should convert the data to 16 bit signed integers. It works for the first 12 values. The 13th value is wrong, followed by zeros.
The second problem is that the program seems to enter the while loop only once.
I am using Windows + MinGW.
My Code:
#include <iostream>
using namespace std;
#define DEFAULT_BUF_LENGTH (16 * 16384)
int main(int argc, char* argv[])
{
char buf[DEFAULT_BUF_LENGTH];
while(cin >> buf)
{
int16_t* data = (int16_t*) buf; //to int
for(int i=0;i<18;i++)
{
cout << data[i] << endl;
}
}
return 0;
}
Output:
0
9621
-14633
-264
5565
-12288
9527
-7109
11710
6351
4096
-5033
5773
147
0
0
0
0
Thanks for your help!
>>
it converts line endings. You have to use unformatted input functions likecin.read()
. en.cppreference.com/w/cpp/io/basic_istream