0

First of all I'm newbie at c/c++ and probably answer for my question will be very simple for You.

I have to move data from monochrome .bmp (it is scanned 2D shape of element) to bool array (0- white, 1 - black). I found this toppic: Converting 1-bit bmp file to array in C/C++

and I have to do the same thing but this code is i C and I need to do it in C++ so how i have to change it so it would work in C++? (I'm using VSexpress 2010)

edit 1: this bmp is 144x320 pixels

edit 2: i see non of You even look at code, there is problem with pointer error C2440: 'initializing' : cannot convert from 'void *' to 'unsigned char ' 1> Conversion from 'void' to pointer to non-'void' requires an explicit cast it is in line: unsigned char *img = malloc(w * h), *data = malloc(fileSize);

Community
  • 1
  • 1
  • Without looking at the link, you can probably use the exact same code. C++ is (more or less) a superset of C, so all statements and expressions available in C is available in C++ too. – Some programmer dude Oct 22 '13 at 07:37
  • You should be more specific as for how your images are stored - and for image processing in c++ I would recommend using openCV – zenpoy Oct 22 '13 at 07:37
  • Since the size is fixed, you can use arrays in C++ as well. C++ is mostly C compatible if you do not use STL so I think you can compile that code with C++ compiler. – Cengiz Kandemir Oct 22 '13 at 07:40

2 Answers2

0

I think C code will mostly work in C++ without any modification, considering the functions used are quite common. You can change the file operation to use fstream, but using fopen and C functions should also work.

rcs
  • 6,713
  • 12
  • 53
  • 75
0

The C code you link to should work as is in C++ - the latter being a superset of the former. You could of course migrate the C code to C++ idioms (using STL, etc.) but I would suggest against it.

Note however that if said code does not compile, it might be because your C++ compiler is asking for high standard respect, so (see here why) "#include <stdio.h>" shall be replaced by "#include <cstdio>", "#include <string.h>" by "#include <cstring>", "#include <memory.h>" by "#include <cstdlib>".

Community
  • 1
  • 1
Noe
  • 386
  • 1
  • 5