ofstream valid path and name
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: ofstream valid path and name

  1. #1
    Join Date
    Jan 2003
    Posts
    615

    ofstream valid path and name

    The following code writes to a file on either local disk to a remote disk (commented out code) on Windows 7 platform.

    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    int main () 
    {
      ofstream outfile;
      outfile.open ("test.txt");
      //outfile.open ("\\\\server/temp/test.txt");
      outfile << "Hello world";
      outfile.close();
      return 0;
    }
    The documentation does not specify what is a valid filename (path and filename). For example, will the "\\\\server\temp" path work on all operating systems to access a samba share? Does the constructor accept forward and backward slashes as folder separator on all operating systems?
    Before post, make an effort yourself, try googling or search here.

    When posting, give a proper description of your problem, include code* and error messages.

    *All code should include code tags

  2. #2
    Join Date
    Apr 1999
    Posts
    27,418

    Re: ofstream valid path and name

    Quote Originally Posted by laasunde View Post
    The documentation does not specify what is a valid filename (path and filename).
    That is because a valid name depends on the operating system, and the C++ specification says nothing about what makes a file name valid.
    For example, will the "\\\\server\temp" path work on all operating systems to access a samba share? Does the constructor accept forward and backward slashes as folder separator on all operating systems?
    I believe for standard C++ I/O functions, both forward and backward slashes are used as directory separators. For OS specific I/O functions (such as CreateFile), then the OS decides what is the directory separator.

    Regards,

    Paul McKenzie

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center