Sign in to follow this  
SpowNzz

Read VS resource text file with iostream

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this