Columns and formating

Started by
3 comments, last by lordoftools 18 years, 8 months ago
Hi i used to used Borland C++ like 3 years ago and then hadn't used C++ again until now. In borland there was a way to space out text into columns (for a console app) and i want wondering how i could do that in MSVC++? I don't even remember how i used to do it or else i'd try it out first and also it could be different or not possible with MSVC++ but i don't see why there wouldn't be a function or something to do it. Please if someone could give me a very simple piece of source code of like two words being printed into 2 columns or soemthing like that i'd appreciate it. Thank you -Lordoftools
-Lordoftools"Knowledge is not only a gift it's a responcibility."
Advertisement
It could be you were just using tab characters ('\t'). Ex:
#include <iostream>int main(){  std::cout << "col 1\tcol 2" << std::endl;  std::cout << "word 1\tword 2" << std::endl;	return 0;}
No im sry it was not '\t', i've been using that right now and it's not working out well because values in the first column change and always messes the spacing up somehow....right now i've been writeing my own functions which add a buffer of spaces to the end of the first column values so that they will all have teh same string length and be lined up ok, but im having some variable convertion problems and would like to know if there was an easy way.

in borland it was something like this but i know im missing some code and maybe have some wrong code:

cout.setf(ios::fixed);
cout.width(20); cout<<"Blah";
cout<<"column 2";

-Lordoftools
-Lordoftools"Knowledge is not only a gift it's a responcibility."
Then you probably want the std::setw() manipulator in the <iomanip> header, and possible also std::setfill() or std::setprecision().
YES! cout::setprecision() i remember that from when i used Borland could you please give some sample code for it? Im not familiar with C++ yet to read a header name or something like that and beable to hunt it down and learn it too easily yet.

Thanks
-Lordoftools
-Lordoftools"Knowledge is not only a gift it's a responcibility."

This topic is closed to new replies.

Advertisement