how to save ping results in a text file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • india215
    New Member
    • Mar 2009
    • 1

    how to save ping results in a text file

    Hello all,

    Iam trying to save the ping results obatined in a text file in c++.

    Below is a copy of my code. Any advice will be greatly appreciated.

    I keep getting this error:

    c_str()) was unexpected at this time.
    Code:
    #include <iostream>
    #include <string>
    #include <windows.h>
    
    using namespace std;
    
    static string host;
    static string ping_again;
    
    void ping()
    {
         int j,ep;
         char wait1;
         j=2;
         
         cout << "Host: ";
         cin >> host;
         
             
         for(ep1=0;ep1<k;ep1++)
         { 
         
        
         
         
         system ("(ping + host).c_str()) >> myfile.txt ");
         
         
         //system("dir > myfile.txt");
         
         cout << endl;
         }
         
         cout<< "wait";
         cin>>wait1;
    }
    
    int main()
    {
         SetConsoleTitle("Ping in C++ by india215");
         ping();
         
         return(0);
    }
    Last edited by pbmods; Mar 9 '09, 12:49 AM. Reason: Added CODE tags.
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    The problem is this line
    system ("(ping + host).c_str()) >> myfile.txt ");

    Create the string with required args and then pass the same to system and u will get the desired results.


    Raghu

    Comment

    Working...