Hey, Im trying to get the user to type in a file name, and then the program will copy the file to some where else like C:\ or USB or something.
So far this is what I've come up with:

#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <conio.h>
#include <fstream>
#include <string>

using namespace std;


int main()
{
    string file;
    cout << "Enter name the file, TO THE EXACT WORD!!! eg. \"Hi.txt\" :\n"; 
   
    getline(cin, file);
   
    system ("copy \" file.c_str \" \"C:\\Ok.txt"\ "); 

    getch();
    return 0;
}

The problem there is that when i do file.c_str(), the system thinks is the name of the file, and says it cannot be found.
Thanks for any help..:icon_neutral: :icon_confused:

If you want to do it with the system() command, you could do something like:

int main(void)
{
    string file;
    cout << "Enter name the file, TO THE EXACT WORD!!! eg. \"Hi.txt\" :\n"; 
    getline(cin, file);
    string command = "copy " + file + " C:/Ok.txt";
    system (command.c_str()); 

    cin.get();
    return 0;
}

But I wouldn't recommend it. You might want to read this thread.

You can also see that I've replaced getch() with cin.get(). Getch isn't a standard c++ function and requires you to include the conio header (which also isn't standard). It would be a good thing to learn yourself to use cin.get() in the future to pause your program, or you could just run your program from a console and there wouldn't be a need to pause your program.

Thanks, but I'll just stick to the system() command for now, I'm feeling confused with iterators

This question has already been answered. Start a new discussion instead.