-8

Here is my code:

    rename("tmp.png", Filename);

The 2nd argument in the rename function is a string.(The user decides what the name is) How do I properly code this so that tmp.png is renamed to whatever the user types?

My instructor says to use c_str somehow, But I'm not sure how.

This is my first post, Let me know if it's hard yo understand or If I'm asking it wrong somehow..

Moo-Juice
  • 38,257
  • 10
  • 78
  • 128
Jarm Welch
  • 1
  • 1
  • 1
  • There's also this thing called Google search. It's great, check it out! – LogicStuff Nov 03 '15 at 19:45
  • Possible duplicate of [How to convert a std::string to const char\* or char\*?](http://stackoverflow.com/questions/347949/how-to-convert-a-stdstring-to-const-char-or-char) – jpo38 Nov 03 '15 at 20:18
  • Sorry, I didn't know what to search on google, I'm a complete beginner with programming, so please forgive me. I'll try harder with Google next time before asking.. Thanks – Jarm Welch Nov 04 '15 at 14:51

1 Answers1

10

It's hard to say, but have you tried that:

rename("tmp.png", Filename.c_str());

If Filename is a std::string std::string::c_str() converts it to a const char*, which is maybe what needs your rename function as second argument?

If you are trying to use standard rename function, this may solve your problem.

jpo38
  • 20,821
  • 10
  • 70
  • 151
  • Thank you so much, I searched google for a long time, I just didn't what I should be searching, exactly. This solved my problem. – Jarm Welch Nov 04 '15 at 14:50