Sign in to follow this  
lordoftools

Columns and formating

Recommended Posts

lordoftools    102
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

Share this post


Link to post
Share on other sites
SiCrane    11839
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;
}

Share this post


Link to post
Share on other sites
lordoftools    102
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

Share this post


Link to post
Share on other sites
SiCrane    11839
Then you probably want the std::setw() manipulator in the <iomanip> header, and possible also std::setfill() or std::setprecision().

Share this post


Link to post
Share on other sites
lordoftools    102
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this