1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Saving Files in C++

Discussion in 'Software Development' started by Regicide, Dec 14, 2003.

Thread Status:
Not open for further replies.
  1. Regicide

    Regicide Thread Starter

    Aug 8, 2003
    I want to make a program that will save files in C++. I want to save the files 1000 bytes at a time. This the code I have so far:
    #include <iostream.h>
    #include <fstream.h>
    #include <string.h>
    int main()
    	ofstream out;
    	ifstream in;
    	int X = 0;
    	char buffer;
    	char szTotal[1000];
    	in.open("C:\\Folder\\Program2.exe", ios::in | ios::binary);
    	out.open("C:\\Program.exe", ios::out | ios::trunc | ios::binary);
    		if(X == 1000)
    			X = 0;
    			out << szTotal;
    		szTotal[X] = buffer;
    	szTotal[X] = '\0';
    	out << szTotal;
    	cout << "Done" << endl;
    	return 1;
    When I do this, the whole file isn't saved. I don't want to use filebufs to save/store the file. Any suggestions?
  2. coderitr


    Oct 12, 2003
    Your code looks ok to me. What part of the file is not being saved? Is the target always a certain amount too small?
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/187284

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice