Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Strings. I'm missing something.

Author
Message
Merak Spielman
16
Years of Service
User Offline
Joined: 14th Jul 2008
Location:
Posted: 9th Jun 2009 08:05
This is bugging the hell out of me. This should be basic C++ stuff, like I figured out over a year ago. I've used strings so many times.

Why don't they work here?

Basically I'm creating a "tile" class, and one of its variables is supposed to be a string. This string will be something like "forest.png" so I can have tiles for basic terrain types.

Should be EASY.

Like this:



Yeah, so I'm still working on it. But even this basic class won't work. It behaves like the string class doesn't exist:

error C2065: 'string' : undeclared identifier

What's going on? How can I hold the filename if I can't use strings?
ABXG
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Canada
Posted: 9th Jun 2009 08:24
You didn't declare "using namespace std;".

------------------------------------
Currently 1500+ lines of code into an "over-the-shoulder" action RPG with combat based on rag-doll physics.
jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 9th Jun 2009 15:20
alternatively, replace string with std::string

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 9th Jun 2009 18:21
Alternatively, add 'using std::string' to your code

jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 9th Jun 2009 18:49
I never use usings, because it can cause clashes when using multiple libraries.

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 9th Jun 2009 19:18
Quote: "I never use usings, because it can cause clashes when using multiple libraries."


Never had that before. Besides, if you ever need to get it back to char* form, you just gotta do (char*)str.c_str().
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 10th Jun 2009 01:29 Edited at: 10th Jun 2009 01:29
Quote: "it can cause clashes when using multiple libraries"

That's why you only use 'using std::string' rather than 'using namespace std'. That way only the string class is imported

Merak Spielman
16
Years of Service
User Offline
Joined: 14th Jul 2008
Location:
Posted: 10th Jun 2009 20:00
I'm getting confused because I still have a problem and it's a different one than I remember.

When I stick:

#include <string>

anywhere in my code, I get compiler errors. Simply telling it to add that library makes it unable to compile, whether or not I try to actually use a string.

Here is the compiler error (Visual Studio 2008 Express):

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 10th Jun 2009 20:08
Click Project->Project Properties (bottom one)->Configuration Properties->C/C++->Code Generation, and set the Runtime Library to /MT.

That should fix it.
Merak Spielman
16
Years of Service
User Offline
Joined: 14th Jul 2008
Location:
Posted: 10th Jun 2009 20:11
Thank you! That worked.

I assume that's documented somewhere and I just missed it? Do I have to set it for each project individually?
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 10th Jun 2009 20:23
You have to set it for any project that uses std or, probably, any third party library that has a debug version. DGDK doesn't have a debug version so it causes some clashes. The alternative is to compile in Release mode but that means you can't debug very well.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office

Login to post a reply

Server time is: 2024-11-05 23:04:37
Your offset time is: 2024-11-05 23:04:37