.
unsigned int fname_length = 0; //fname length equals 30 file.read((char*)&fname_length,sizeof(unsigned int)); //fname contains random data as you would expect char *fname = new char[fname_length]; //fname contains all the data 30 bytes long as you would expect, plus 18 bytes of random data on the end (intellisense display) file.read((char*)fname,fname_length); //m_material_file (std:string) contains all 48 characters m_material_file = fname; // count = 48 int count = m_material_file.length(); now when trying this way, intellisense still shows the 18 bytes of data after setting the char array to all ' ' and I get exactly the same results. even without the file read
char name[30]; for(int i = 0; i < 30; ++i) { name[i] = ' '; } file.read((char*)fname,30); m_material_file = name; int count = m_material_file.length(); any idea whats going wrong here, its probably something completely obvious but im stumped!
thanks
sizeof(unsigned int)since it ties your binary file format to the platform - the number of bytes for anunsigned intis a platform specific detail.