setw within a function to return an ostream
here is my function
ostream margain(std::string firstWord)
{
ostream x;
x << std::setw(20) << firstWord;
return x;
}
in main I want to use the function as follow
std::cout<< margain("start") << "````````````````````````````````````" <<
std::endl;
// print things out
//then
std::cout<< margain("End") << "````````````````````````````````````" <<
std::endl;
I get the output, start or end is not shown, and the return value is
0````````````````````````````````````
how can I fix it? and why?
Edit: I know that the function is what causing that, because if I add this
cout << std::setw(20) << firstWord; in the function, It prints right
No comments:
Post a Comment