Problem Mortgage | Mortgages | Loans | Credit Card Consolidation | Loans
TAB in C++ [Archive] - PCMech Forums

PDA

View Full Version : TAB in C++


bolsey84
04-29-2004, 09:17 AM
Anyone know how to insert a tab in a cout statement? I have a value in an array that i want to tab each value... for example...

cout << currentLED[x].color << currentLED[x].voltage << currentLED[x].current << currentLED[x].bright << currentLED[x].angle << currentLED[x].partnum << endl;

I want a tab between each part of the array where the << sign is

Thanks in advance

AerynSedai
04-29-2004, 09:42 AM
cout <<
currentLED[x].color << "\t"
currentLED[x].voltage << "\t"
currentLED[x].current << "\t"
currentLED[x].bright << "\t"
currentLED[x].angle << "\t"
currentLED[x].partnum << "\n";
the "\t" is the escape character for tab, "\n" is the escape character for newline. stick with endl as it is more portable, but it is there for demonstration. "\\" will give you a backslash. "\"" will give you a quote. and so on. there are many escape sequences for all the things that are normally syntax related characters. don't go over 80 characters or you will spill over on next line on a dos terminal.

AS

bolsey84
04-29-2004, 09:50 AM
Thanks, but i get a ton of compile errors when i put in the stamenet you gave me... 22 errors

AerynSedai
04-29-2004, 10:00 AM
what are they?

AS

AerynSedai
04-29-2004, 10:01 AM
cout <<
currentLED[x].color << "\t" <<
currentLED[x].voltage << "\t" <<
currentLED[x].current << "\t" <<
currentLED[x].bright << "\t" <<
currentLED[x].angle << "\t" <<
currentLED[x].partnum << "\n";

silly me, forgot the other stream operators after the "\t"

AS

bolsey84
04-29-2004, 10:04 AM
Well, i do not get any errors now, but my output is really messed up. Are you allowed to tab when you are outputting a string? it gives me all these negative values

AerynSedai
04-29-2004, 10:14 AM
it doesn't do that when you print out without the "\t"s?
it seems like it is casting it as an integer.
that's weird.

cout << "hello" << "\t" << 5 << "\t" << 10 << "\t" << "foobar" << "\n";prints fine for me using g++. i don't know what to say. i usually use printf() for formatted text, but this should work all the same and should not change anything.

if you want, you can post some of the code, but i won't be back for two hours.

AS