Archived

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

steve1992

File Streams

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