Thread: Using fstream and ip addresses

  1. #1
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640

    Using fstream and ip addresses

    Is something like this legal? It doesn't work right now, but is it possible to do something like this?

    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    int main()
    {
        char c[51];
        fstream infile("64.237.35.121:78");
        if (!infile)
            cout << "Can't open address" << endl;
        infile << "BARF" << endl;
        while (infile >> c)
            cout << c;
        cin >> c;
        return 0;
    }
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> Is something like this legal?
    For a type other than fstream...sure.

    >> is it possible to do something like this?
    Yep. You could define TCP stream types or UDP stream types ect...

    gg

  3. #3
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    What do you mean for a type other than fstream? I know what sockets are and such, but this idea popped in my head.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    I only meant that fstream doesn't work on sockets directly...

    gg

  5. #5
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Oh, I thought it could, since it can open files across a LAN. So winsock is your only choice on windows?
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> I thought it could, since it can open files across a LAN.
    Network File Systems are typically transparent to the application. Under Windows you use UNC paths or mounted volumes.
    Under *nix, NSF drives are equally transparent to the application.

    >> So winsock is your only choice on windows?
    That or some 3rd party library that does what you want.

    gg

Popular pages Recent additions subscribe to a feed