Jump to content
Korean Random

Лишний раз записывается буфер в файл. [C++][Решено]


Recommended Posts

int main()
{
	char buff[4];
	std::ifstream file("Hull_mask.primitives", std::ifstream::binary);
	std::ofstream out("Hull_mask_enc.primitives", std::ifstream::binary);
	while (file) {
		file.read((char*)&buff, sizeof buff);
		out.write((char*)&buff, sizeof buff);
	}
	file.close();
	system("pause");
	return 0;
}

лишний раз записывается содержимое буферной переменной.

post-18657-0-89180700-1505599385_thumb.png

Решил так:

	while (file) {
		file.read((char*)&buff, sizeof buff);
		if (!file.eof())
			out.write((char*)&buff, sizeof buff);
Edited by Pavel3333
  • Upvote 1
Link to comment
Short link
Share on other sites

Это не C++ way)

А я по-всякому пробовал. Если делать file >> buff, это работает до первого нулевого символа. То есть дальше 7 байт я не уйду.

StreamReader? Не люблю CLR, только хардкор. :)

Link to comment
Short link
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...