Just a quick question, is it possible to pass C++ strings from main into a function. May sound simple but it's not working for me.
Also does anyone know of a good tutorial on writing to and reading from a .txt file.
Thanks for your help.
Just a quick question, is it possible to pass C++ strings from main into a function. May sound simple but it's not working for me.
Also does anyone know of a good tutorial on writing to and reading from a .txt file.
Thanks for your help.
You mean something like this:
Output:Code:#include <string> #include <iostream> void func(std::string str) { std::cout << str << std::endl; } int main() { std::string str = "Hello World"; func(str); }
Code:Hello World
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
You mean something like this:
As you probably know, I think the string class is complex enough to pass a const reference instead of making a copy.Code:#include <string> #include <iostream> void func(const std::string& str) { std::cout << str << std::endl; } int main() { std::string str = "Hello World"; func(str); }
Thanks for your input on this, they have both helped me in my functions, sorry to be so vague but the prob is i'm only starting my development and very little to offre by way of concrete code.