strings as parameter/argument
Dec 28, 2012 at 10:13am UTC
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?
Dec 28, 2012 at 10:17am UTC
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!
Dec 28, 2012 at 10:23am UTC
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 Dec 28, 2012 at 2:47pm UTC
Dec 28, 2012 at 10:34am UTC
@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 ~
Dec 28, 2012 at 11:09am UTC
@ 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.