[Dev-C++] How would you write a method returning a string ?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Hiroyuki Y. <yam...@gm...> - 2007-07-21 15:22:50
|
Hi, I'm wondering how you would write a method returning a string. In C, we usually return char * which malloced in the function or returning char * which is static in the function. (We should free the char * in the first case.) In C++, we have std::string, so i'm not sure what to do with it to return string. What I'm trying to do as following. 1. use char * as a return value just like C 2. use std::string as a return value (copying the string object) 3. use std::string reference as one of the arguments (return value is bool or something.) 4. use std::string reference as a return value There should be more ways, but I'm not familier with those (teach me those please) and I don't know what's the best. I'm going to use method 2 because it's simple and copying string object is not a much cost I think. (It's said that string object is 7 times as big as the pointer size(4bytes) at the biggest in Effective STL) Please let me know how you would write to return string. Thanks, HIroyuki Yamada |