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

  1. #1
    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,817
    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.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    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,817
    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 09:01 AM.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    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,817
    That too.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

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, 12:47 PM
  5. compile problem
    By eriaug in forum C++ Programming
    Replies: 7
    Last Post: 11-10-2004, 10:18 PM