Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 04-29-2004, 08:17 AM   #1
Member (6 bit)
 
Join Date: Oct 2002
Location: Ohio
Posts: 32
TAB in C++

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
bolsey84 is offline   Reply With Quote
Old 04-29-2004, 08:42 AM   #2
Member (7 bit)
 
Join Date: Sep 2003
Posts: 90
Code:
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
AerynSedai is offline   Reply With Quote
Old 04-29-2004, 08:50 AM   #3
Member (6 bit)
 
Join Date: Oct 2002
Location: Ohio
Posts: 32
Thanks, but i get a ton of compile errors when i put in the stamenet you gave me... 22 errors
bolsey84 is offline   Reply With Quote
Old 04-29-2004, 09:00 AM   #4
Member (7 bit)
 
Join Date: Sep 2003
Posts: 90
what are they?

AS
AerynSedai is offline   Reply With Quote
Old 04-29-2004, 09:01 AM   #5
Member (7 bit)
 
Join Date: Sep 2003
Posts: 90
Code:
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
AerynSedai is offline   Reply With Quote
Old 04-29-2004, 09:04 AM   #6
Member (6 bit)
 
Join Date: Oct 2002
Location: Ohio
Posts: 32
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
bolsey84 is offline   Reply With Quote
Old 04-29-2004, 09:14 AM   #7
Member (7 bit)
 
Join Date: Sep 2003
Posts: 90
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.

Code:
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
AerynSedai is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 12:53 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2