Results 1 to 8 of 8

Thread: open file

  1. #1

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    open file

    Code:
    #include "iostream.h"
    #include "fstream.h"
    #include "stdafx.h"
    
    int getdir();
    
    int getdir()
    {
    int i;
    ofstream out("C:/Matt/text3.txt");
    
    if(!out) {
    		MessageBox(NULL,"Cannot open output file","Error",MB_OK);
    		return 1;
    }
    
    for(i=0;i<256; i++) out.put((char) i);
    
    out.close();
    
    	return 0;
    }
    im using MVC++ and i get errors. This worked on my old compiler but not MS's. What am I doing wrong here? Thanks
    Matt

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Code:
    #include "iostream.h"
    #include "fstream.h"
    #include "stdafx.h"
    Put iostream.h and fstream.h inside angle-brackets <>. What's in stdafx.h? You shouldn't need it since you're not using MFC.

    Code:
    if(!out)
    Try if(out.fail()).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Where are the errors?

    Usually you use angled brackets for headers like that, and quote headers for headers you make yourself. It makes a difference to the order in which paths are searched for header files. Maybe that's making it go wrong. It's easier to diagnose problems when you have error messages.
    Harry.

    "From one thing, know ten thousand things."

  4. #4
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Ah well okay Parksie already posted
    Harry.

    "From one thing, know ten thousand things."

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Originally posted by HarryW
    Ah well okay Parksie already posted
    Hehe sorry
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    You realise I'll never forgive you for this. I'm just devastated.
    Harry.

    "From one thing, know ten thousand things."

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Sure you are You'll just have to get me back for it some other time then
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  8. #8

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    here are the errors theres still problems with it.
    here are the headers.

    #include <iostream.h>
    #include <fstream.h>

    mywinapp.cpp
    C:\MATT\MVC++\MSDEV98\MyProjects\mywinapp\mywinapp.cpp(99) : error C2143: syntax error : missing ';' before '.'
    C:\MATT\MVC++\MSDEV98\MyProjects\mywinapp\mywinapp.cpp(99) : error C2143: syntax error : missing ';' before '.'
    C:\MATT\MVC++\MSDEV98\MyProjects\mywinapp\mywinapp.cpp(101) : error C2065: 'out' : undeclared identifier
    C:\MATT\MVC++\MSDEV98\MyProjects\mywinapp\mywinapp.cpp(101) : error C2228: left of '.fail' must have class/struct/union type
    C:\MATT\MVC++\MSDEV98\MyProjects\mywinapp\mywinapp.cpp(106) : error C2228: left of '.put' must have class/struct/union type
    C:\MATT\MVC++\MSDEV98\MyProjects\mywinapp\mywinapp.cpp(108) : error C2228: left of '.close' must have class/struct/union type
    Error executing cl.exe.
    Matt

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