#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    64
    Rep Power
    11

    FIFO: Writing out multiple lines from C++


    I have this function:

    Code:
    int sysstat() {
    
        std::ifstream fifoOut("hpaneld.fifo");
        
            fifoOut << std::endl << "\n Current Memory usage: \n" << std::endl;
                   fifoOut << system("free");
    
            fifoOut << std::endl << "\n Current Disk Usage: \n" << std::endl;
                   fifoOut << system("df -h");
    
            fifoOut << std::endl << "\n System Info: \n" << std::endl;
                   fifoOut << system("uname -a");
    
            fifoOut << std::endl << "\n Uptime: \n" << std::endl;
                   fifoOut << system("uptime");
    
            fifoOut << std::endl << "\n Running Processes: \n" << std::endl;
                   fifoOut << system("ps au");
    
            fifoOut << std::endl;
    
            return 0;
    }
    Which gathers system statics and should put them into the FIFO for the client frontend to read. But it wont compile:

    stats.cpp: In function `int sysstat()':
    In file included from hpanel.cpp:4:
    stats.cpp:4: no match for `ifstream & << ostream & ()(ostream &)'
    stats.cpp:7: no match for `ifstream & << ostream & ()(ostream &)'
    stats.cpp:10: no match for `ifstream & << ostream & ()(ostream &)'
    stats.cpp:13: no match for `ifstream & << ostream & ()(ostream &)'
    stats.cpp:16: no match for `ifstream & << ostream & ()(ostream &)'
    stats.cpp:19: no match for `ifstream & << ostream & ()(ostream &)'
    I believe it's the way i implemented writing out to fifo. Please help :)
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    4
    Rep Power
    0
    I messed with your code and here is what I did. First you have ifstream for your file but should be ofstream. Next you are tryng to use the output of the sytem() call but that will not work it returns a int not the output of the call. The best I came up with was that you could have the call output to the file inside of the system call i.e {system("free >> hpaneld.fifo")} here is a modified version but still needs work because of the file being appended at the end and wirting the "header" part inline. If I think of something i'll post


    Mileto->Frank

    #include <stdlib.h>
    #include <fstream.h>
    int main(){
    std::ofstream fifoOut("hpaneld.fifo");

    fifoOut << std::endl << " Current Memory usge: " << std::endl;
    system("free >> hpaneld.fifo");
    fifoOut << std::endl << " Current Disk Usage: " << std::endl;
    system("df -h >> hpaneld.fifo");
    fifoOut << std::endl << " System Info: " << std::endl;
    system("uname -a >> hpaneld.fifo");
    fifoOut << std::endl << " Uptime: " << std::endl;
    system("uptime >> hpaneld.fifo");
    fifoOut << std::endl << " Running Processes: " << std::endl;
    system("ps au >>hpaneld.fifo");
    fifoOut << std::endl;
    return 0;
    }
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    64
    Rep Power
    11
    Thanks, havent tested it yet, bu at least it compiles without errors :)

IMN logo majestic logo threadwatch logo seochat tools logo