strings as parameter/argument

I am a c++ beginner and I don't know if strings can be used as argument, if yes then please give any easy example?
Yes, they can.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iomanip>
#include <iostream>
#include <string>

void printString(std::string s)
{
    std::cout << s << std::endl;
}

int main()
{
    std::string s("Hello, World!");

    printString(s);
}
Hello, World!

I think he is confused about using the "old way strings".
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

void printString(const char* s)
{
    std::cout << s << std::endl;
}

int main()
{
    char s[] = "Hello World";

    printString(s);
}
Last edited on
@NeeteshDad If you need help with string/char (or passing them as arguments into functions in different ways), just PM me and I'll gladly help you fully understand that.

~ Raul ~
@ NeeteshDad: please don't PM any one person - keep it on the forum so that more of us can see and help.
Topic archived. No new replies allowed.