Programs communication

Hello,

I tried to write two programs that communicates with each other through fstreams directer to the same file. It works.

But here comes a question - are there other ways? Streams are quite slow, and while fstreams work faster than standard input/output streams, I thought maybe there are some other, better ways?

Maybe there is a way to directly tie output stream of one file with the input stream of another?

I heard you can do that with sockets and its probably faster, but I'm quite a novice when it comes to programming, and those seem a fair bit above my level of skill and experience.



Here is a simplified version of what I did, if you didn't get what I mean:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//file 1

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    const int size = 100;

    char* buffor;
    buffor = new char[size];

    ifstream is("buffor1.txt",ios::in);
    ofstream os("buffor2.txt",ios::out);

    os<<"ala ma kota"<<'\0';

    delete[]buffor;

    return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//file2

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    const int size = 100;

    char* buffor;
    buffor = new char[size];

    ifstream is("buffor2.txt",ios::in);
    ofstream os("buffor1.txt",ios::out);

    is.get(buffor, size, '\0');

    cout<<buffor;

    delete[]buffor;

    return 0;
}


ala ma kota
Google "Interprocess Communication" also known as IPC. And you'll find endless reading on how to make applications communicate.
Topic archived. No new replies allowed.