Jump to content
  • Advertisement


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

The C modest god

Writing and reading string class

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

It''s working perfectly fine for me.

$ cat foo.cc
#include <iostream>
#include <fstream>
#include <string>

int main()
std::string a="test", b;
std::ofstream outf("a.fl", std::ios::binary);
std::ifstream inf("a.fl", std::ios::binary);


std::cout << b << std::endl;

And don''t use [code‍] blocks if you''re not willing to replace your < with &lt;

Share this post

Link to post
Share on other sites
I have noticed that when I read the string, I get the string and the string I wrote afterwards. I assume that writting a string in binary does not put ''\0''.
Therefore I need to put it explicitly.
My question is, does endl functions as ''\0''?

Share this post

Link to post
Share on other sites
No. endl works as ''\n'', and >> reads whitespace-delimited words. Opening a file in ''binary mode'' doesn''t mean the data is read/written in binary, only that (platform-dependent) newline translation is not done.

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!