Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

steve1992

File Streams

This topic is 5460 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

const char* LoadData() { getline(InFile,str,''\n''); // str const char* data = str.c_str(); return data; } InFile.open("data.txt"); const char* bs = LoadData(); //bitmap image The line from .txt document isnt recognized by LoadSurfaceFromFile. Works ok in a console.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
you are returning a pointer to a variable that goes out of scope.

const char *data

so you''re reading a pointer to something that may not be anything.

const char* bs = LoadData();

you''ll need to revise

Share this post


Link to post
Share on other sites
What's wrong with std::string?

template <typename CharT, typename Traits>
inline void LoadData(std::basic_istream<CharT, Traits>& is, std::basic_string<CharT, Traits>& str)
{
std::getline(is, str);
}

Or this, if you aren't too bothered about generic code:

inline void LoadData(std::istream& is, std::string& str)
{
std::getline(is, str);
}


std::ifstream in_file("data.txt");

// ...


std::string bs;
LoadData(in_file, bs);

// ...



[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]

[edited by - Lektrix on October 15, 2003 11:09:31 AM]

Share this post


Link to post
Share on other sites

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