By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,227 Members | 1,376 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

how copy the content of the "fstream::rdbuf()" to a string?

P: n/a
Hi, hot heart men:
I have a program in file input and output. I need copy the whole source file's content to a string only once, I don't know what? Help me? thank you.

wukexin
wu*****@sina.com

Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
wukexin wrote:
I have a program in file input and output. I need copy the whole

source file's content to a string only once, I don't know what? Help me?
thank you.

Read my thread "fileToString" (use http://groups.google.com and search for
my street name & fileToString).

I went with this:

std::string fileToString(std::string const& name) {
std::ifstream in(name.c_str());
std::ostringstream out;
out << in.rdbuf();
return out.str();
}

--
Phlip
http://www.c2.com/cgi/wiki?TestFirstUserInterfaces


Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.