how to put file or files on usb drive for other computer use

hi everyone, how do i copy a file( or files ) on a main computer and paste it on a usb drive to be used on a different computer, all help is appreciated, thanks,
You drag and drop.


If you want a program to do that, that's no problem as long as you know the directory that the flash drive will make (F: is the drive name on my machine and probably most people's). From there, it's just a matter of using ofstream.


1
2
3
4
5
6
7
#include <fstream>

int main()
{
	std::ofstream outFile;
	outFile.open("F:\\Racism.txt");
}



EDIT: If you also want to copy a file, here's some simple code I found to do it:

1
2
3
4
5
6
7
8
9
#include <fstream>

int main()
{
	std::ifstream  inFile("Racism.txt", std::ios::binary);
	std::ofstream  outFile("F:\\Racism.txt", std::ios::binary);

	outFile << inFile.rdbuf();
}
Last edited on
You can do that with the filesystem library in C++ 17.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <string>
#include <filesystem>

int main() {
  std::string fn;
  std::string cpLoc;
  std::cout << "Enter filename to be copied: ";
  std::getline(std::cin, fn);
  if(!std::filesystem::exists(fn)) {
    std::cerr << "Error: " << fn << " file does not exist\n";
    return 1;
  }
  std::cout << "Copy to where: ";
  std::getline(std::cin, cpLoc);
  if(!std::filesystem::exists(cpLoc)) {
    std::cerr << "Error: the directory does not exist\n";
    return 1;
  }
  std::filesystem::copy(fn, cpLoc);
  return 0;
}
Hi and thank you for the responses... but I have found a way on youtube that does what i want to do. here is the link:

https://www.youtube.com/watch?v=AvrjQtFBJvk

with this I can run a program(console) from a usb drive.. I would like to know if I can put this runnable program/folder from the USB drive and copy and paste it to a computer desktop and run it that way

thanks again
Why don't you try? It should just work, as long as you're going from Windows to Windows. (And if you're building a 64-bit exe, then that can't be run on a 32-bit system).

If it complains about a runtime redistributable being needed, that might need to be installed.
tried it, Ganado, it worked, thank you, copied and pasted it
Topic archived. No new replies allowed.