I
I
igoodmood2016-09-23 15:55:48
C++ / C#
igoodmood, 2016-09-23 15:55:48

How to set the path to create a file?

There was a question: the task of a way for creation of a file.
Tried to implement it like this:

string name, fullname, location;
  ofstream file;
  cout << "Введите имя: ";
  cin.sync();
  getline(cin, name);
  getline(cin, location);
  fullname = location + name;
  file.open(fullname.c_str());
  file.close();

But for some reason the file is not created at the specified path.
If we replace the 7th line with this:
fullname = ("C:\\Users\\Владимир\\Desktop\\") + name;

Then everything is created. But I need the user to enter the path himself.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
romy4, 2016-09-23
@romy4

Try debugging name and location first;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question