open file dialog

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Cleves
Posts: 224
Joined: Mon Sep 08, 2003 6:40 pm

Post by Cleves »

He says std dosn't exist, do i need to include any header or lib?

Thanks
Gorgon Zola
Posts: 118
Joined: Thu Sep 18, 2003 10:05 pm
Location: switzerland

Post by Gorgon Zola »

Cleves wrote:He says std dosn't exist, do i need to include any header or lib?
Ah, well... you need to include some standard template library (STL) stuff
in windows under visual studio 2003 i need to include
#include <string> // for std::string
#include <locale> // for std::locale
#include <fstream> // for output stream

just look in the docu of your system,
or google for standard template library.

if you need to get a char* just use the method ".c_str()" of the string object (took me a while to find that when i was new to STL).

if you don't have a compliant compiler there is an STL porting project at www.stlport.com

btw, stl uses std as namespace. (what a beauty :lol:, i just love cryptic phrases)

cheers
gorgon
Cleves
Posts: 224
Joined: Mon Sep 08, 2003 6:40 pm

Post by Cleves »

Well it seems to work but dosn't there any easier way doing that? i can't understand the use of getfilename if that's the process i need to do,isn't there anything shorter that will give me the same result?

Thanks
Gorgon Zola
Posts: 118
Joined: Thu Sep 18, 2003 10:05 pm
Location: switzerland

Post by Gorgon Zola »

Cleves wrote:Well it seems to work but dosn't there any easier way doing that?
if you want to have byte-characters to work with then I'm afraid there isn't any shorter way (But I could be wrong :wink: )

if you just want to output the filename a shorter method would be to use
a 'std::wofstream'

Code: Select all

#include <fstream>
...
std::wofstream appLog;
wchar_t* msg=L"hello unicode world"; 

// note: 'wchar_t' is a type def for 'unisgned short' !
...
appLog.open("applog.txt");

...
// write some text stored in msg
appLog<< msg;
...
cheers
gorgon
Cleves
Posts: 224
Joined: Mon Sep 08, 2003 6:40 pm

Post by Cleves »

Thanks Gorgon. :D

I have another question. I want to read from a file using irrlicht.
but i got some problems,compiles well but there is an runtime error.here is my code:

IReadFile* fl;
device->getFileSystem()->createAndOpenFile("output.txt");
fl->read(filename,100);

Any ideas?
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

Well, you would first want to make sure your file exists as it may be a path problem. C++ can set a different working directory as compared to where the application is run from.

if (device->getFileSystem()->existFile("output.txt") {
}

or it might be somewhere else

if (device->getFileSystem()->existFile("c:\output.txt") {
}

The second would be "Is your read buffer, which you call filename, large enough to hold 100 characters or is there any other problems related to it?"

Code: Select all

virtual s32 irr::io::IReadFile::read  (  void *    buffer,  
  s32    sizeToRead 
 )  [pure virtual] 
 
   Reads an amount of bytes from the file. 

Parameters: 
buffer:  Pointer to buffer where to read bytes will be written to.  
sizeToRead:  Amount of bytes to read from the file.  

Returns: 
Returns how much bytes were read.  
Crud, how do I do this again?
Post Reply