Hi freinds.
please read this code.
When I run this code in VC++, I get the output as 0,1. It shoyld come as 0, 1, 2......9. Does any one can tell me why could this happen?Code:int main() { int i = 0; for(i=0;i<10;i+=1) cout << i; }
Hi freinds.
please read this code.
When I run this code in VC++, I get the output as 0,1. It shoyld come as 0, 1, 2......9. Does any one can tell me why could this happen?Code:int main() { int i = 0; for(i=0;i<10;i+=1) cout << i; }
cout is buffered. Try calling cout.flush() after your output. Calling << endl will also flush the buffer.
it works ok for me in VC++ 6.0. This is the output. If you want spaces and commas then you have to program them, cout will not do that for you.
Code:0123456789Press any key to continue
Aren't there modifiers that do that sort of thing?If you want spaces and commas then you have to program them, cout will not do that for you.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
To my limited knowledge of c++ iostreams, there are no such modifiers.
you could try
Code:for(int i; i <10; i++) { i+=1; cout << i << endl; }
Are you sure you want the i+=1;?
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
oops, yeah, make that i a x or something..