Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Can you put a string in a called function, where the string is in the parameter? In C++?

For example,

void call(test)

{

if test = "hello"

{

cout << "hi";

}

}

void main()

{

call("hello")

}

would I get an output of "hi"?

Update:

forgot to add & next to void call(&test), if it matter...but the main question is would "hello" be passed?

1 Answer

Relevance
  • 6 years ago
    Favorite Answer

    yes

    #include <string>

    void call(std::string const & test)

    {

    if (test == "hello")

    {

    cout << "hi";

    }

    }

Still have questions? Get your answers by asking now.