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;
}
6
  • system(("say " + sums).c_str()); Commented Oct 28, 2017 at 23:02
  • 2
    Also "Why is “using namespace std” considered bad practice?". Commented Oct 28, 2017 at 23:05
  • system takes a pointer to constant character string not class string. Commented Oct 28, 2017 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. Commented Oct 29, 2017 at 4:14
  • @Eryn I know, it wasn't a question. :) It's a title of the question I wanted to show the OP. Commented Oct 29, 2017 at 10:03

1 Answer 1

2

You can use:

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

Instead of:

system("say %s", sums)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.