Printf() vs cout: function versus stream

Pages: 12
Aug 17, 2011 at 11:54pm
I wish that there was a pre-formatting utility


Have you see Boost Format??
http://www.boost.org/doc/libs/

Not sure it's exactly what you're looking for, but it allows you to use format strings with ostreams.

(nicked from Boost's docs)

1
2
3
4
5
    using namespace std;
    using boost::format;
    using boost::io::group;

    cout << format("%1% %2% %3% %2% %1% \n") % "11" % "22" % "333"; // 'simple' style. 



Last edited on Aug 17, 2011 at 11:55pm
Aug 18, 2011 at 6:13am
Read his whole post, his employers forbid him to use open source stuff.
Aug 18, 2011 at 10:31am
Yes, but the pre-formatting utility is already in the standard:

printf( "Hello %s!\n", name );

1
2
sprintf( s, "Hello %s!\n", name );
cout << s;

cout << (ostringstream() << "Hello " << name << "!\n").str()

If it is that big a deal, write your own that works exactly like the Boost one.
Aug 18, 2011 at 9:05pm
@GisleAune

Read his whole post, his employers forbid him to use open source stuff.

I don't see a post from graham sullivan containing this info?
Aug 18, 2011 at 9:24pm
You were quoting kempofighter.
Aug 18, 2011 at 9:31pm
@kempofighter. It is a pity you have a blanket ban on all open source. Boost is not like a random open source library you find lying about the web, as "(m)any of Boost's founders are on the C++ standards committee ..."

http://en.wikipedia.org/wiki/Boost_C%2B%2B_Libraries

Andy

Last edited on Aug 18, 2011 at 9:31pm
Aug 18, 2011 at 10:20pm
closed account (1yR4jE8b)
especially when many job projects that I am on forbid me from using open source


Why? Is it a licensing issue? Because many different open-source licenses do not require you to open-source your code if you use it in certain ways: BSD, MIT, even Boost has it's own license.
Aug 19, 2011 at 1:15am
It's a corperate lawyer issue.
Aug 19, 2011 at 3:20am
I read an article elsewhere even the term Open Source is open to lawyer interpretations. Within Open Source there are BSD,MIT etc and according to some lawyers it does not indicate total "freedom" as in no need to pay monies to use etc.

How I wish someone unify and come to terms on a SINGLE Open Source license. This can save a lot of headaches for us developers when we propose certain Open Source libraries to our employers to do certain task and yet not infringe on any intellectual property issues with those Open Source libraries developers/organizations.
Aug 19, 2011 at 3:40am
Unfortunately: http://xkcd.com/927/
Aug 19, 2011 at 4:54am
there are BSD,MIT etc and according to some lawyers it does not indicate total "freedom" as in no need to pay monies to use
Well, I don't know what you may have read, but those two in particular are examples of royalty-free licences. In fact, the only requirement they make is to give credit (more or less); it's even possible to relicense to anything you want.

How I wish someone unify and come to terms on a SINGLE Open Source license.
That wouldn't make any sense for a variety of reasons.
Topic archived. No new replies allowed.
Pages: 12