-1

I'm trying to learn C++. I have a little bit of python in my background. Is there anyway to do the string formatting in C++ just like I did in python using format?

class Employee{ public: int pay; string Lname; string Fname; string email;

    Employee(int apay, string aLname, string aFname){
        pay = apay;
        Fname = aFname;
        Lname = aLname;
        email = "%s.%s@gmail.com", aFname, aLname;

    // in python i could do email = "{}.{}@gmail.com".format(aFname, aLname)

I expect the output of cout << emp1.email; to be first.last@gmail.com.

Emma
  • 27,428
  • 11
  • 44
  • 69
Kevin S
  • 1
  • 1
  • sorry if im asking dumb questions. im new to programming. – Kevin S Jul 20 '19 at 22:06
  • Completely valid @mjarosie as the question even though it has the same answer is on itself a different question which helps those who google – zardilior Jul 20 '19 at 22:10
  • What you want is C++20s format library: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0645r9.html. the reference implementation can be found at https://github.com/fmtlib/fmt – JVApen Jul 20 '19 at 22:13

1 Answers1

0

You can use

std::operator+ (string)

like this email = aFname+"."+ aLname+"@gmail.com";

check this link for more informations.