0

/* I thought of doing in this way, but it invalid. so any help will be appreciated. */

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;
int main()
{
   string name = "Karma";
   string greet = "How was your day?";
   string sums = name + greet;

   system("say %s", sums) // not working
   // system("say sums")  not working

   return 0;
}
tintin
  • 1
  • 2
  • `system(("say " + sums).c_str());` – HolyBlackCat Oct 28 '17 at 23:02
  • 2
    Also "[Why is “using namespace std” considered bad practice?](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice)". – HolyBlackCat Oct 28 '17 at 23:05
  • `system` takes a pointer to constant character string not `class string`. – Raindrop7 Oct 28 '17 at 23:11
  • @HolyBlackCat, I think it has something to do with overloading functions or library confusion and many of our friends here on Stackoverflow consider it lazy coding. The non- "using namespace... " way of doing it is for every cout or cin is to write it std::cout or std::cin. – Eryn Oct 29 '17 at 04:14
  • @Eryn I know, it wasn't a question. :) It's a title of the question I wanted to show the OP. – HolyBlackCat Oct 29 '17 at 10:03
  • @HolyBlackCat lol. Oops! Thanks for letting me know. Guess I didn't realize that it was a link! – Eryn Oct 29 '17 at 16:12

1 Answers1

2

You can use:

system(("say" + sums).c_str())

Instead of:

system("say %s", sums)