Forum Topic: basic c++ question

(184 views • 8 replies)

This topic is 1 page long.

<< < > >>
Happy

Pinoyguy75

Reply To Post Reply & Quote

Posted at: 6/28/09 10:20 PM

Pinoyguy75 EVIL LEVEL 24

Sign-Up: 04/30/02

Posts: 332

So I know '/t' is to add a tab after a word, but I forgot how to adjust that value (8 i think) to make it bigger or smaller. Can anyone remind me how this is done?


None

henke37

Reply To Post Reply & Quote

Posted at: 6/29/09 07:34 AM

henke37 NEUTRAL LEVEL 22

Sign-Up: 09/10/04

Posts: 3,548

Nope, not possible, c++ does not have any screen, so you can not control how a tab character will be interpreted.

Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.


None

kiwi-kiwi

Reply To Post Reply & Quote

Posted at: 6/29/09 07:55 AM

kiwi-kiwi LIGHT LEVEL 08

Sign-Up: 03/06/09

Posts: 630

Actually it should be '\t' and you can try to use printf in your advantage here

printf("%xs","something");

Substitute x with the value you want for the tab.


Happy

malganis85

Reply To Post Reply & Quote

Posted at: 6/30/09 01:09 PM

malganis85 DARK LEVEL 02

Sign-Up: 06/30/09

Posts: 2

kiwi-kiwi I think he is talking about c++ you posted c.

1. The world is full of fascinating problems waiting to be solved 2. Freedom is good 3. no problem should ever be solved twice 4. Boredom and drudgery are evil

BBS Signature

None

Wonderful

Reply To Post Reply & Quote

Posted at: 6/30/09 01:12 PM

Wonderful FAB LEVEL 13

Sign-Up: 07/27/08

Posts: 856

At 6/30/09 01:09 PM, malganis85 wrote: kiwi-kiwi I think he is talking about c++ you posted c.

I don't know a lick of C++ and I still know you can use C functions in C++ code.

That must say alot about you, then.

Posted from Linux. Distro may vary.


None

kiwi-kiwi

Reply To Post Reply & Quote

Posted at: 6/30/09 02:43 PM

kiwi-kiwi LIGHT LEVEL 08

Sign-Up: 03/06/09

Posts: 630

At 6/30/09 01:09 PM, malganis85 wrote: kiwi-kiwi I think he is talking about c++ you posted c.

Yeah, I know, I use C++ mostly for OOP and memory management (I'm too lazy to use malloc), so I know C a lot better than C++.
Anyway, like wonderful said, C code works in C++, so if a quick solution is available in C, why not use it?


None

djconnect

Reply To Post Reply & Quote

Posted at: 6/30/09 03:09 PM

djconnect EVIL LEVEL 18

Sign-Up: 01/13/07

Posts: 822

It is perfectly logical to use C code in C++. C++ is just an extension of C, so in a way C code is C++ code but not vise versa.

I am a hacker of a Nu-Aira

BBS Signature

None

jmbpiano

Reply To Post Reply & Quote

Posted at: 7/4/09 04:20 AM

jmbpiano NEUTRAL LEVEL 03

Sign-Up: 07/04/09

Posts: 7

At 6/30/09 02:43 PM, kiwi-kiwi wrote:
At 6/30/09 01:09 PM, malganis85 wrote: kiwi-kiwi I think he is talking about c++ you posted c.
Anyway, like wonderful said, C code works in C++, so if a quick solution is available in C, why not use it?

That's *mostly* true but when dealing with C console output functions things tend to get funky. Things work just fine if you only use C++ iostreams or if you only use the C output functions, but as soon as you start mixing them things can get out of sync quickly. You can end up with a situation where you do a

printf("Hello");
cout << "world";
printf("/n");

and your output is "worldHello"

You can mix them, but you have to make sure you call fflush() and cout.flush() every time you switch back and forth. It can be a headache and it's generally better to pick one set of functions and stick with it.

To answer the original question, to do any kind of formatting in C++, you want to use the functions in the iomanip header. If you want to output 5 spaces, you would do this:

#include <iostream>
#include <iomanip>

[snip]

   cout << setw(5) << ' ';

If you want to display 20 asterisks, you would do this:

#include <iostream>
#include <iomanip>

[snip]

   cout << setfill('*") << setw(5) << ' ';

None

jmbpiano

Reply To Post Reply & Quote

Posted at: 7/4/09 04:25 AM

jmbpiano NEUTRAL LEVEL 03

Sign-Up: 07/04/09

Posts: 7

Ugh....

That last example should have been

#include <iostream>
#include <iomanip>

[snip]

   cout << setfill('*") << setw(20) << '*';

This forum really needs an edit button- and I really need to go to bed. :/


All times are Eastern Standard Time (GMT -5) | Current Time: 11:53 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!