mIRC Home    About    Download    Register    News    Help

Print Thread
Page 2 of 3 1 2 3
#139753 21/01/06 04:19 PM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
you got 2 choices. or you comment the "using namespace std" line and use std:: in front of all the types that need it OR you uncomment the line and remove std:: in front of all the types that need it.

A namespace is a realm in which the code is defined.

you can define some code in a namespace like this

namespace blah {

typedef bloh int;
}

blah::bloh myvar = 4;

if I insert this

use namespace blah;

then I can only use

bloh myvar = 4;

#139754 21/01/06 05:20 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
ok nice one, made a fair bit of progress thanks to you but this is a bit shocking. The below code gives 0 errors, but 121 warnings LOL. and also, it prints Mark twice (in the exe window) where it should print Mark, and then Harry, as I changed the data from mark to harry

Code:
// hhh.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <map>
#include <string>
using namespace std;

typedef std::map<std::string, std::string> MyMap;
MyMap TestMap;

int main() {

	std::string chan( "#Channel" ); //keytype
	std::string mark( "Mark" );     //datatype

	TestMap.insert( MyMap::value_type( chan, mark ) );
	MyMap::iterator it = TestMap.find( chan );
	//this should print Mark
	if ( it != TestMap.end( ) ) {
		printf( (*it).second.c_str( ) ); 
		printf("\n");
	}

	//change #channel value from Mark to Harry
	TestMap.clear;
	std::string harry( "Harry" );
	TestMap.insert( MyMap::value_type( chan, harry ) );

	//this should now print Harry
	if ( it != TestMap.end( ) ) {
		printf( (*it).second.c_str( ) );
		printf("\n");
	}

	return 0;
}


Last edited by pouncer; 21/01/06 05:20 PM.
#139755 21/01/06 07:40 PM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
I think you misunderstood me on the "using namespace std;"

if you use it, you have to omit the std:: in front of the types you use that come from the library. If you don't, you have to insert them in front or the system will say he can't find the type you are using.

And .clear( ) is a function not an argument. I compiled this code on VC++2003 and it works like a charm and prints the names correctly.
Code:
#include <stdio.h>
#include <map>
#include <string>


//using namespace std;

typedef std::map<std::string, std::string> MyMap;

MyMap TestMap;

int main() {

	std::string chan( "#Channel" ); //keytype

	std::string mark( "Mark" );     //datatype

	TestMap.insert( MyMap::value_type( chan, mark ) );

	MyMap::iterator it = TestMap.find( chan );

	//this should print Mark

	if ( it != TestMap.end( ) ) {

		printf( (*it).second.c_str( ) ); 

		printf("\n");

	}

	//change #channel value from Mark to Harry

	TestMap.clear( );

	std::string harry( "Harry" );

	TestMap.insert( MyMap::value_type( chan, harry ) );

	//this should now print Harry

	if ( it != TestMap.end( ) ) {

		printf( (*it).second.c_str( ) );

		printf("\n");

	}

	return 0;

}

#139756 21/01/06 09:05 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
:S this is very odd then, im doing something badly wrong then because I get

Linking...

hhh.exe - 0 error(s), 122 warning(s) which prints Mark twice in the c:\hhh\hhh.exe debug exe when i click on

execute hhh.exe from the build menu :S

(im using the exact code you pasted)

the version im using is visual c++ 6.0, and its all in a win32 console application, hope someone can tell me if im doing anything wrong, i really would like to get this working, thanks guys

Last edited by pouncer; 21/01/06 09:37 PM.
#139757 21/01/06 10:33 PM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
try putting this at the top

#pragma warning( disable : 4530 )

I know the STL is a little hippy about warnings sometimes.

But I can't see what you are doing wrong, make sure you use the code I provided. Could also be your compilator (or mine) which doesn't compile stuff the same way.

#139758 21/01/06 10:54 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
d*mn, stil the same problem,

i dont know what to do now :S

if its not of any hassle david, is there any chance you could upload the project you made it in as a zip, so i can see if it compiles on mine?

Last edited by pouncer; 21/01/06 10:59 PM.
#139759 22/01/06 02:47 AM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
the whole code I have, I already posted it, there is nothing more.

#139760 22/01/06 01:50 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
is there any chance you could see if this compiles for you please mate?

www.geocities.com/pouncer_123456/hhh.zip

thanks david

#139761 22/01/06 03:00 PM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
Remake a new project and select "Empty project" instead of the choice you made that includes precompiled headers (the stdafx.h .cpp files which you really don't need and may be causing more harm than good in your case).

I never use them either.

#139762 22/01/06 04:20 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
ok thanks, ive dont exactly that, and for some reason it gives me 123 warnings still (and stil prints the names wrong), you can see it in the build log and heres the small project

www.geocities.com/pouncer_123456/testNew.zip

the code is exactly the same as yours, its kind off spoilt all the plans i had for this dll, i cant do anything now :S

i noticed many of those errors had this in it

c:\program files\microsoft visual studio\vc98\include\map

heres the map file which i found in that directory, not sure if there might be a problem with that

http://www.geocities.com/pouncer_123456/map.txt

Last edited by pouncer; 22/01/06 04:27 PM.
#139763 22/01/06 04:31 PM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
remove that ; after the first #include

and I said clearly that TestMap.clear is a function not an attribute and should be

TestMap.clear( ); <----

The rest compiles fine here, noe warnings or errors and returns

Mark
Harry

I think you aren't too familiar with C programming to make these kinds of omissions, maybe you should invest time to learn C/C++ before trying to tackle this type of problem which is obviously a little intermediate to advanced stuff. This demo is simple, but it can get ugly quickly if you want to add more stuff to it.

#139764 22/01/06 06:48 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
ok, corrected both of those things you said, still the 123 warnings (no errors though)

and prints names wrong

i give up, i dont know why an earth this is happening, must be the map class on my pc or something?

erm hangon, are you only compiling it from the 'build' menu?
i got 0 error, 0 warning when i did that

but when i click on 'rebuild all' thats where all the warnings come up

Last edited by pouncer; 22/01/06 06:55 PM.
#139765 22/01/06 07:26 PM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
I get 0 errors when I rebuild all, build, or any other compile options.

You should try to install SP4 of Visual Studio 6 and also the latest SDK with the latest libs.

#139766 22/01/06 11:36 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
yeah ok thanks, im just hoping its a problem with my c++ version installed or something.

Ill try reinstalling it some other time now, but just lie to say a big thanks to you david on this thread.

#139767 24/01/06 10:36 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
sorry for bringing this thread back david but just a quick Q,

Code:
#include &lt;string&gt;
using namespace std;
typedef map&lt;string, string&gt; MyMap;
MyMap TestMap;


i removed the std::'s, as im 'using namespace std', but it just keeps saying

error C2143: syntax error : missing ';' before '<'

like 4 times :S

#139768 24/01/06 11:04 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
If you want to use a map, you need to include the header for it:

#include <map>


Gone.
#139769 24/01/06 11:38 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
ok thanks sorted that part, got it about 90% working now. but im trying to return an entry in a seperate function (and storing an entry in another function)

Code:
	string channel = data;
	iT = KeyStorer.find(channel);

	string key = (*iT).second.c_str( );

	_fstrcpy(data, key.c_str());
	return 3;


as you see above the data is the channel name i ffed into the dll parameter, keyStorer is the map instance name, its definately storing the key, but its just crashing my mirc when i use the above code to grab the key, any ideas guys?

ive got all this stored at the top

typedef map<string, string> MapFunction;
MapFunction KeyStorer;
MapFunction::iterator iT;

Last edited by pouncer; 24/01/06 11:39 PM.
#139770 25/01/06 02:43 AM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
Code:

string channel = data;

MapFunction::iterator it = KeyStorer.find( channel );

if ( it != KeyStorer.end( ) )
 lstrcpy( data, (*it).second.c_str( ) );
else
  lstrcpy( data, "Key Not Found" );

return 3;

#139771 25/01/06 02:53 AM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
thanks for the reply, this is very weird. heres the code

Code:
//stuff at the top for maps etc
typedef map&lt;string, string&gt; MapFunction;

MapFunction KeyStorer;
MapFunction::iterator iT;

extern "C" int WINAPI StoreKey(HWND, HWND, char *data, char *parms, BOOL, BOOL) {

	string channel = GetTok(data, 1, 32);
	string key = GetTok(data, 2, 32);

	KeyStorer.insert(MapFunction::value_type(channel, key));

	return 1;
}

extern "C" int WINAPI GetKey(HWND, HWND, char *data, char *parms, BOOL, BOOL) {

	string channel = data;
	MapFunction::iterator it = KeyStorer.find( channel );

	if ( it != KeyStorer.end( ) ) 
		lstrcpy( data, (*it).second.c_str( ) );
	else  
		lstrcpy( data, "Key Not Found" );
	
	return 3;
}


//.dll Test.dll StoreKey #hello testkey

then

//echo -a $dll(Test.dll, GetKey, #hello) - should echo testkey but it just echos 'no key found' :S

Last edited by pouncer; 25/01/06 03:01 AM.
#139772 25/01/06 10:51 AM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
then I'm sorry to say that your code to insert is flawed with that Gettok stuff

Look at your insert params to see what is going on

Page 2 of 3 1 2 3

Link Copied to Clipboard