# [c++] Problem with std::string...

This topic is 4123 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey, first of all sorry about the poor discription of this topic but I would have no idea how else to describe this problem. My code is as follows:
// -- Header --
// Structure HeightMap
struct HEIGHTMAP { USINT heightData[100*100]; };


// -- Source Main--

// Create TestMap
HEIGHTMAP TestMap;


// -- Source Class LoadMap --
{
// Open mapPath And Load Data Into mapArray
std::ifstream InputFileMap;

InputFileMap.open( mapPath.c_str(), std::ios::in | std::ios::binary );

if (InputFileMap.is_open())
{
InputFileMap.read((char*)(*mapArray).heightData, sizeof(USINT) * 100 * 100);

InputFileMap.close();

this->Logger->Notify("Heightmap Opened Correctly! File: " + mapPath);
} else {
this->Logger->Error("Could Not Open Heigtmap File! File: " + mapPath);
}

return;
}


Now if I debug this in the LoadMap function mapArray has the structure of an std::string. Meening when I look at mapArray in the Watch window I get a structure like this: - mapArray {...} + std::_String_val<char,std::allocator<char> > {...} + _Bx {...} _Myres 0 _Mysize 0 npos 4294967295 The interesting thing is that everything seems to be working fine when I switch the order of arguments in LoadMap like this:
void classMapLoader::LoadMap(HEIGHTMAP* mapArray, std::string mapPath);


Now I'm not sure why this is and any help would be greatly appreciated. If there is any request for more code I'll post it asap. Quinnie

##### Share on other sites
thats kind of messed up,
what compiler + debugger are you using?

##### Share on other sites
Sorry I forgot to mention that, I'm using Visual c++ 2003 .Net

##### Share on other sites
Have you tried cleaning and rebuilding the project?

Are you certain that you don't have two copies of the header file lying around? Like, ANYWHERE on your hard disk?

##### Share on other sites
Cleaning and rebuilding unfortunetly did not help, I'm also quite positive this is the only file with that name on my harddisk.

Also it might help to mention that with an other function I made I have the same problem, again switching the arguments seems to help.

##### Share on other sites
Aside from the weird debugger information, what actually happens when you run the code?

##### Share on other sites
Well, after the read function, where the array should be filled with data from the file, the std::string structure gets filled out with nonsense really. Also I can not acces the elements of mapArray (It is an unsigned short int array from 0 to 100000). When I switch the arguments as mentioned before the array gets filled out nicely and I can access the elements.

##### Share on other sites
Are all of your source files correctly including the header file? I've seen compilers pass the first argument to a function OK, but any other ones get messed up if the function hasn't been prototyped. Just a thought.

##### Share on other sites
Yeah, if the prototype has the arguments the wrong way around, it could cause this sort of problem. The compilation process may not spot the error since the total argument size is identical in both cases.

##### Share on other sites
Quote:
 Original post by f8k8Are all of your source files correctly including the header file? I've seen compilers pass the first argument to a function OK, but any other ones get messed up if the function hasn't been prototyped. Just a thought.

Any C++ compiler should prohibits this (and this is the case for VC++ 2003). A function has to be declared (or defined) before any use (like any other symbol).

• 33
• 12
• 10
• 9
• 9
• ### Forum Statistics

• Total Topics
631354
• Total Posts
2999489
×