| | |
Manipulators
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2008
Posts: 8
Reputation:
Solved Threads: 1
Hi i am trying to understand manipulators. Can someone explain what is happening here
For the first time, i mean in the first iteration of the loop, it prints correctly but from the second iteration, the output always seems to be right justified. Why?
Here is the output of the above loop
C++ Syntax (Toggle Plain Text)
for (int i = 0; i < n; i++) { cout << setiosflags(ios::left) << setw(15) << item[i] << setw(8) << setprecision(0) << code[i] << setiosflags(ios::right) << setw(8) << setprecision(2) << setiosflags(ios::fixed | ios::showpoint) << cost[i] << endl; }
For the first time, i mean in the first iteration of the loop, it prints correctly but from the second iteration, the output always seems to be right justified. Why?
Here is the output of the above loop
C++ Syntax (Toggle Plain Text)
dsjfh 102 32.32 jdshfjd 120 1212.00 dfdsfdsf 322 32.23
Last edited by sweeya; Dec 19th, 2008 at 4:16 am.
•
•
Join Date: Aug 2008
Posts: 206
Reputation:
Solved Threads: 31
The short answer is that ios::left and ios::right (and some others) are not mutually exclusive, but your code reflects an assumption that they are. It is possible to have both set simultaneously and, of so, it is up to the implementation to decide which one (or a combination) applies.
Try using resetiosflags() manipulators to restore the various flags to their defaults before each line of output.
Try using resetiosflags() manipulators to restore the various flags to their defaults before each line of output.
Define your own manipulators, make a code simpler:
http://www.java2s.com/Tutorial/Cpp/0...anipulator.htm
http://www.java2s.com/Tutorial/Cpp/0...anipulator.htm
![]() |
Similar Threads
- C++ homework (C++)
- Right Justified / decimal point alignment (C)
- the beginner needs help (C++)
- c++ arrays, help identify element place (C++)
- Need direction on how start this program (C++)
- Need direction on how start this programm (C++)
- The Calculator (C++)
- I need special stuff in my project like system("cls") (C++)
Other Threads in the C++ Forum
- Previous Thread: Error while compilation in the args of the function
- Next Thread: Items in combobox do not appear. (visual studio 6.0)
Views: 700 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






