Jump to content
  • Advertisement
Sign in to follow this  
SpowNzz

Read VS resource text file with iostream

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone, I have one question....lets say i have a VS resource file (like menus, dialogs, bitmaps,but the resource in my APP is text file). Is there a way to read from this text file with iostream? Or can u give me a hint how to do it anyway. I need the same functionality that iostream give me too read the whole line or just some words, but i want the file to be as a resource in my application or in resource only dll. Ty all.

Share this post


Link to post
Share on other sites
Advertisement
This would be one solution:


// This function is the aquivalent to the explode function of php
void explode( std::string str, const std::string &separator, std::vector<std::string> &results )
{
std::size_t found;
found = str.find_first_of(separator);

while( found != str.npos )
{
if( found > 0 )
{
results.push_back( str.substr( 0, found ) );
}
str = str.substr( found + 1 );
found = str.find_first_of( separator );
}

if( str.length() > 0 )
{
results.push_back( str );
}
}

// Somewhere in your code
std::ifstream file( "main.res" );
std::string contents( (std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>() );

std::vector<std::string> lines;
explode( contents, "\n", lines );



contents will now contain the file as it is, whereas the vector contains one entry for each line in the file. You will have to take care of different line endings though (I'm no expert in this, but I believe unix does \r\n).

Share this post


Link to post
Share on other sites
Ty, i will try it and will say if everything is OK or if i have some other related problems.

P.S. As far as i know windows platform use \r\n and linux just \n. But if someone know better lets share with us :).

Ty again.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!