0

How i can make the user enter the path of the xml file to be saved?

I want the user to enter something like "c:\test.xml" and the xml file is generated by that name and location.

I tried

 string PathName;
 cin >> PathName;
XMLDocument doc;
doc.SaveFile(PathName);

but it gives me the error

 no instance of overloaded function matches the argument list 

I know its such a simple question but somehow I am stuck, sorry

Alice
  • 15
  • 3

1 Answers1

0

I think your error is telling the parameter type doesn't match an overload. Try this instead:

auto result = doc.SaveFile(PathName.c_str());

Edited to include result from the function - if it fails it should give you an error code. Quoting the docs:

Save the XML file to disk. Returns XML_SUCCESS (0) on success, or an errorID.

castro
  • 409
  • 3
  • 13
  • now the program works but it does not save the file by the inserted name and path – Alice Jun 04 '20 at 17:42
  • You need to provide more information then. What is the filename/path you are passing in? How are you running the program? – castro Jun 04 '20 at 18:02
  • I want the user to enter the path to where the file should locate and the name for it. For example the input is "c:\test.xml" the program saves the file in c with the name test. I am using VS2019 – Alice Jun 04 '20 at 18:05
  • If you are trying to save to the C drive (as opposed to a user directory) make sure you are running VS with admin privileges – castro Jun 04 '20 at 18:06
  • I am running it with admin privileges, also I am trying to save it to anywhere really, it depends on the user – Alice Jun 04 '20 at 18:09
  • Try checking the return from the function - edited my answer with more info. – castro Jun 04 '20 at 18:44
  • Btw I have just tried this myself and it works. If there is more to your code, please share it. Also consider hard-coding your filename to remove the possibility of user input error. – castro Jun 04 '20 at 19:14