I made a win32 application in Visual C++ 2008 using the Windows Forms Application. But for opening files, and saving eventually, havn't gotten to it yet, I was creating some basic classes in other files.
The odd thing is the stdio.h file seems to be working differently in VC. I tried compiling the same code in Code::Blocks, which worked without problems.. Yet VC is still giving me a hard time figuring out what exactly is wrong.

Map.cpp

#include "stdafx.h"
#include "Map.h"
#include <stdio.h>


Map Map::openMap(Stringgg fileName)
{
	Map theMap;
	int x,y;
	char myString[1000];
	const char* FileName = fileName.GetStringgg();
	File* pFile;
	pFile = fopen(FileName, "r+b");
	
	if(pFile != NULL)
	{
		fgets(myString, 1000, pFile);
		fscanf(pFile, "%d %d", &x, &y);
		theMap.SetName(fileName);
		theMap.SetX(x);
		theMap.SetY(y);
		while(!feof)
		{
			fgets(myString, 1000, pFile);
			int ID, z;
			fscanf(pFile, "%d %d %d %d", ID, x, y, z);
		}
	}
	else
	{
		theMap.SetName("New map");
		theMap.SetX(200);
		theMap.SetY(200);
		Stringgg Error = "Couldn't open map. Creating new map(200x200)...";
		MessageBox(NULL, Error, NULL, MB_OK);
		return theMap;
	}
}

Map.h

#ifndef MAP_H_INCLUDED
#define MAP_H_INCLUDED

#include "Position.h"
#include "String.h"

class Map
{
	public:
		Map() {}
		Map(int x, int y): itsX(x), itsY(y) {}
		~Map() {}

		Stringgg GetName() {return itsName;}
		int GetX() {return itsX;}
		int GetY() {return itsY;}
		//Position GetPosition(int x, int y, int z);

		Stringgg SetName(Stringgg name) {itsName = name;}
		void SetX(int x) {itsX = x;}
		void SetY(int y) {itsY = y;}
		//Position SetPosition(int x, int y, int z, int ID);

		Map openMap(Stringgg fileName);
		//void saveMap(Stringgg fileName);
	private:
		Stringgg itsName;	//Name of the map
		int itsX;			//Size of the map; x-axis
		int itsY;			//Size of the map; y-axis
		Position* itsPositions;	//Positions on the map
};

#endif //MAP_H_INCLUDED

Don't mind the functions that are commented out in Map.h.. Left them out as I'm still stuck.

Stringgg is just a self-made string class because the windows String class was refusing to be used inside the classes for some reason... Called that way to avoid the names being ambigous. Position is another class in a seperate header file.
Neither of them is really needed, since the errors:

1>Compiling...
1>Map.cpp
1>.\Map.cpp(12) : error C2065: 'File' : undeclared identifier
1>.\Map.cpp(12) : error C2065: 'pFile' : undeclared identifier
1>.\Map.cpp(13) : error C2065: 'pFile' : undeclared identifier
1>.\Map.cpp(15) : error C2065: 'pFile' : undeclared identifier
1>.\Map.cpp(17) : error C2065: 'pFile' : undeclared identifier
1>.\Map.cpp(18) : error C2065: 'pFile' : undeclared identifier
1>.\Map.cpp(22) : warning C4551: function call missing argument list
1>.\Map.cpp(24) : error C2065: 'pFile' : undeclared identifier
1>.\Map.cpp(26) : error C2065: 'pFile' : undeclared identifier
1>.\Map.cpp(35) : error C2065: 'MB_OK' : undeclared identifier
1>.\Map.cpp(35) : error C3861: 'MessageBox': identifier not found

Somehow seems as if the "stdio.h" doesn't recognize the type File.. Yet considering MessageBox gives an error too there's probably something else wrong too..
Or that might just because I forgot to include something..

Thanks for any input.. [Probably something stupid anyway]

Member Avatar for iamthwee

>while(!feof)
Definitely not a good idea to use.

>Stringgg
What's wrong with string under the header file #include <string> and if need be converting to a char array using c_str() . Don't complicate issues.

I learned C++ through a book.. And it's author used a String class as an example. So I just followed that along...
And since I'm not familiar with that class, however it will probably be more useful, I find it easier to use this one as long as it's capable of getting the job done...
Saves me some time trying to find what does what again

Compile your project in VC++ 2008 as a console (not Forms) application and you will get the same result as in Code::Blocks (probably, your Code::Blocks IDE used VC++ to make console application)...

Actually I just meant I tried the code for the seperate headers in Code::Blocks, without the form.
Currently trying to find the option for changing it to a console application... Unless I would have to create a console application, and then add all of the files to it?

>>Somehow seems as if the "stdio.h" doesn't recognize the type File
That's correct because there is no such thing in stdio.h -- its FILE (all caps).

>>Somehow seems as if the "stdio.h" doesn't recognize the type File
That's correct because there is no such thing in stdio.h -- its FILE (all caps).

Solved the problem, thanks.

MessageBox is a win32 api function and requires windows.h

>Still doesn't recognize MessageBox() though.. I thought it didn't require any header files?
You thought wrong. You need to make sure that windows.h is included and that you're linking to either user32.lib or user32.dll.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.