A
A
Al3x077032020-06-03 20:45:46
C++ / C#
Al3x07703, 2020-06-03 20:45:46

Error with c++ types?

Error when trying to pass a string containing the username of the computer owner to the CopyFile() function

#include <iostream>
#include <locale>
#include <Windows.h>

using namespace std;

int main()
{
  setlocale(LC_ALL, "ru");
  
  string username = getenv("username");
  string fileName = "TestFile";

  CopyFile("C:\\Users\\"+username+"\\Desktop\\" + fileName + ".txt", "E:\\" + fileName + ".txt");
  
  return 0;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2020-06-04
@Al3x07703

1. C:\Users\XXX\Desktop - not necessarily the table will be there.
2. Google the function std::string::c_str() - convert string to null-terminated C string.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question