Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
mystery segmentation fault involving template
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="nandor.sieben, post: 3480248"] The following program causes a segmentation fault. If I break the print line at the end into two separate print statement then there is no segmentation fault. What is the problem? I am compiling it on Ubuntu Gutsy. using namespace std; #include <iostream> #include <sstream> template < class T > string all2string (T in, int i) { stringstream s; s << in; string ss; ss = s.str (); while (ss.length () < i) ss = "0" + ss; return ss; } typedef struct { int move; int depth; } Tdata; string Tdata2string (const Tdata & data) { string s = all2string (data.depth, 0) + " " + all2string (data.move, 0) + " "; return s; } ostream & operator << (ostream & os, const Tdata & data) { string s = Tdata2string (data); os << s; } main () { Tdata dat; dat.depth = 0; dat.move = -1; cout << dat <<"data \n"; } [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
mystery segmentation fault involving template
Top