no match for 'operator<<' in.... Compile Problem!

This is a discussion on no match for 'operator<<' in.... Compile Problem! within the C++ Programming forums, part of the General Programming Boards category; Hi, Just wondering if anyone can help me out in turning this program into a working program. Basically, everything works, ...

  1. #1
    njd
    njd is offline
    Registered User
    Join Date
    Sep 2005
    Posts
    4

    no match for 'operator<<' in.... Compile Problem!

    Hi,

    Just wondering if anyone can help me out in turning this program into a working program.

    Basically, everything works, apart from inserting the results in the last SYSTEM() line.


    Any help would be greatly appreciated.


    Code:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    
    
    int main()
    {
       string a;
       string b;
       string c;
    
       cout << "Enter source path (where files will be moved from)\n";
       cout << ": ";
       cin >> a;
       cout << "Enter destination path (where files will be moved to)\n";
       cout << ": ";
       cin >> b;
       cout << "Enter minimum access age in days\n";
       cout << "(This will move all files not accessed in x number of days)\n";
       cout << ": ";
       cin >> c;
       cout << c << a << b;
    
       system("robocopy //MOVE //MINLAD:" << c << a << b"");
    
    
    
       system("PAUSE");
       return EXIT_SUCCESS;
    }

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,675
    Code:
    string a;
    string b;
    string c;
    These also require you to #include the <string> header.

    Code:
    system("robocopy //MOVE //MINLAD:" << c << a << b"");
    You can't do it like this. You'll likely need to use either a stringstream or sprintf to format the command.
    I used to be an adventurer like you... then I took an arrow to the knee.

  3. #3
    njd
    njd is offline
    Registered User
    Join Date
    Sep 2005
    Posts
    4
    Quote Originally Posted by hk_mp5kpdw
    Code:
    string a;
    string b;
    string c;
    These also require you to #include the <string> header.

    Code:
    system("robocopy //MOVE //MINLAD:" << c << a << b"");
    You can't do it like this. You'll likely need to use either a stringstream or sprintf to format the command.

    Ah!

    How would I go about doing this?

    I'm pretty much a beginner in C++ and could do with all the help I can get.


    Thanks.

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,675
    Using sprintf:
    Code:
    #include <cstdio>
    
    ...
    
    char buffer[100];
    
    sprintf(buffer,"robocopy //MOVE //MINLAD:%s %s %s",a.c_str(),b.c_str(),c.c_str());
    
    system(buffer);
    Using stringstream:
    Code:
    #include <sstream>
    
    ...
    
    stringstream sstr;
    
    sstr << "robocopy //MOVE //MINLAD:" << a << ' ' << b << ' ' << c;
    
    system(sstr.str().c_str());
    Last edited by hk_mp5kpdw; 01-09-2006 at 08:01 AM.
    I used to be an adventurer like you... then I took an arrow to the knee.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,319
    Or more simply, just use + since they are all strings.
    Code:
    string d = "robocopy //MOVE //MINLAD:" + c + " " + a + " " + b;
    system(d.c_str());

  6. #6
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,675
    That too.
    I used to be an adventurer like you... then I took an arrow to the knee.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  4. compile problem
    By eriaug in forum C++ Programming
    Replies: 6
    Last Post: 12-12-2004, 11:47 AM
  5. compile problem
    By eriaug in forum C++ Programming
    Replies: 7
    Last Post: 11-10-2004, 09:18 PM

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