Results 1 to 5 of 5

Thread: Saving and Opening files (C++)

  1. #1

    Thread Starter
    Addicted Member NewGen's Avatar
    Join Date
    Nov 2002
    Location
    olathe, ks
    Posts
    152

    Saving and Opening files (C++)

    I need to be able to save and open files for a simple boot-up text editor. Can someone tell me how to use the header files ifstream.h and ofstream.h ?
    I suck with graphics. Can you help me out? If you are good with graphics there are rewards . . . email me, [email protected] . . .

    [img src="www.cel-eration.com/anim1.gif"][/img]

  2. #2
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    Here's a simple tutorial from GameDev,

    http://www.gamedev.net/reference/art...rticle1127.asp

    Hope it helps!

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    <fstream.h> is deprecated. Use <fstream>
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    Hyperactive Member made_of_asp's Avatar
    Join Date
    Jul 2001
    Location
    123 Fake Street
    Posts
    394
    C-Style:

    PHP Code:

    #include <stdio.h>

    int load(charsz)
    {
     
    char szBuffer[1024]; 
    FILEfopen(sz"r");
     
    if(!
    f)
    return -
    1;

    while(
    fgets(szBuffer1024f))
    {
     
    printf("%s\n"szBuffer);
    }

    fclose(f);

    return 
    0;

    }

    int save(charszcharszSave)
    {

    FILEfopen(sz"r");
     
    if(!
    f)
    return -
    1;

    fprintf(fszSave);

    fclose(f);

    return 
    0;

    VS.NET 2003

    Need to email me?

  5. #5
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    but he was asking for C++:

    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;
    
    int main()
    {
    	ifstream in("input.txt");
    	ofstream out("output.txt");
    	string str;
    	char c = in.get();
    
    	while(c != EOF)
    	{
    		str += c;
    		cout << c;
    		out.put(c);
    		c = in.get();
    	}
    
    	cout << endl;
    
    	cout << str << endl;
    
    	return 0;
    }
    Last edited by wey97; Jan 2nd, 2003 at 09:37 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width