numbers - std::string

Started by
13 comments, last by Knaperstekt 19 years, 6 months ago
oluseyi:
std::ostream& operator << (std::ostream& os, const vector3& v){   std::stringstream str;   str << "(" << v.x << " " << v.y << " " << v.z << ")";   os << (s+str.str());   return os;}error C2079: 'str' uses undefined class 'std::basic_stringstream<_Elem,_Traits,_Alloc>'        with        [            _Elem=char,            _Traits=std::char_traits<char>,            _Alloc=std::allocator<char>        ]
I had this error with the original non-ostream attempt as well.

joanusdmentia:
    std::stringstream f; f << "f="<<forward;    state.textbox1->DrawStr(0,738,f.str().c_str());error C2079: 'f' uses undefined class 'std::basic_stringstream<_Elem,_Traits,_Alloc>'        with        [            _Elem=char,            _Traits=std::char_traits<char>,            _Alloc=std::allocator<char>        ]error C2297: '<<' : illegal, right operand has type 'const char [3]'

and also because 'forward' is a vector and needs me to teach it how to format itself.

evilcrap: I did not write the matrix library and I would prefer to leave it untouched

/me is becomg very frustrated
Advertisement
I elaborated above including an operator<< operator.
Did you #include <sstream>? It looks like std::basic_stringstream is being forward declared somewhere but not defined.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
Thanks - I appreciate your patience with me. One final question: is there a way to limit to (and force) 4 decimal places (%0.4f)?

Thanks all for walking me through this
Dustin
std::ios_base::width and std::ios::fill.
Quote:Original post by thedustbustr
Thanks - I appreciate your patience with me. One final question: is there a way to limit to (and force) 4 decimal places (%0.4f)?

Thanks all for walking me through this
Dustin


It's probably easiest to use the setprecision manipulator:

str << setprecision(4) << a.b1;

this does not force 4 decimals though, it just maximizes the output to 4 decimals. (isn't that what %0.4f in fstream does as well?)

/Boris

This topic is closed to new replies.

Advertisement