| | |
Copying Files by name input
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
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:
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..
So far this is what I've come up with:
C++ Syntax (Toggle Plain Text)
#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..
C programmers will get smashed by C++ programmers.
If you want to do it with the system() command, you could do something like:
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.
C++ Syntax (Toggle Plain Text)
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.
![]() |
Similar Threads
- Copying of Files from an FTP server (Visual Basic 4 / 5 / 6)
- Dual Boot - Cannot install XP - Stops installing after copying setup files (Windows Vista and Windows 7)
- Automatic Files Sorting and Folders Creation (VB.NET)
- Copying multiple files with Visual Basic (Visual Basic 4 / 5 / 6)
- WD Drive-to-Drive not copying all files (Storage)
- copying in files (C++)
- transfer input.txt to output.txt help prz (C++)
- Inputting from files (C)
- Annoying problem with moving files (Windows NT / 2000 / XP)
- VMWare - transfer files - aaahh! please help (*nix Software)
Other Threads in the C++ Forum
- Previous Thread: composition,aggregation,simple association
- Next Thread: Coding error
Views: 347 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






