|
|
|
|
![]() ![]() |
Nov 25 2006, 12:20 AM
Post
#1
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 537 Joined: 19-May 06 From: Leeds, UK Member No.: 23,963 |
I'm currently learning C++ in college. For now it's very basic stuff (cout, cin, if, switch, voids, etc). But I'm also abit of a "must look neat" freak for certain things. One of which is that I don't like the text on the program being aligned to the right.
For example, I currently have something like this: QUOTE Welcome! Please enter your first name. __ And what's your second name? __ But I want it to be like this: QUOTE Welcome! Please enter your first name. __ And what's your second name? __ My question is simply: how would I do it? This post has been edited by Dagoth Nereviar: Nov 25 2006, 12:21 AM |
|
|
|
Nov 25 2006, 03:38 PM
Post
#2
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 399 Joined: 14-November 04 From: Elysium Member No.: 2,280 |
Hmm... That would depend on how wide your window screen is - as in how many characters it will allow per line.
I refer you to this page. The code on the page assumes that you use a standard 80 character wide line. If you want to use a different one (for whatever reason) just change the '80' value in the code and you'll be fine. Isn't it fun when you don't have to reinvent the wheel? Do tell if you have any problems. |
|
|
|
Nov 25 2006, 04:07 PM
Post
#3
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 537 Joined: 19-May 06 From: Leeds, UK Member No.: 23,963 |
Hahaha, thanks
One quick question (I could probably work it out, but i'm lazy |
|
|
|
Nov 25 2006, 06:34 PM
Post
#4
|
|
|
Premium Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 172 Joined: 2-August 06 From: North Carolina Member No.: 27,662 |
you can just use:
QUOTE #include <conio.h> #include <IOSTREAM.h> #include <bool.h> #include <apstring.h> #include <apstring.cpp> void main() { clrscr(); gotoxy(22,1); cout<<"Welcome! Please enter your first name."; gotoxy(35,2); apstring n1; cin>>n1; gotoxy(27,4); cout<<"And whats your second name?"; gotoxy(35,5); apstring n2; cin>>n2; clrscr(); gotoxy(35,1); cout<<n1<<" "<<n2; getch(); } sample program attached... |
|
|
|
Nov 28 2006, 01:38 AM
Post
#5
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 399 Joined: 14-November 04 From: Elysium Member No.: 2,280 |
Lol. Basically you define it once and call it over and over again.
take that example code from that site again. The function's centerstring right? You'd put the definition of the function anywhere [even outside int main()] -which is the code on the site- (even in a header file if you think you'll use it often enough) and call it whenever you wanted to, e.g. code...centerstring(something);...code. Nice code Tsunami, though I actually prefer just using strlen() and a bunch of manual stuff instead of adding (more like using) apstring. |
|
|
|
Nov 28 2006, 11:20 PM
Post
#6
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 537 Joined: 19-May 06 From: Leeds, UK Member No.: 23,963 |
Thanks to both of you for the code
I like the code Tsunami, but it might make the code waay to long Osknockout, I think I get it Sorry for my noobness |
|
|
|
Nov 29 2006, 12:47 AM
Post
#7
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 399 Joined: 14-November 04 From: Elysium Member No.: 2,280 |
QUOTE Osknockout, I think I get it... but would I put in the "centerstring([something]) What type of noob asks and then says I know? Improper groveling I say...If you look at the function again, you can tell that strlen() already computes the number of characters in your string for you. Actually, that would be your char pointer there Dagoth Nereviar, place your char or char array variable or whatever with characters you want to manipulate in that something. But of course, you already knew that. In case you don't... |
|
|
|
Nov 30 2006, 08:16 PM
Post
#8
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 537 Joined: 19-May 06 From: Leeds, UK Member No.: 23,963 |
What type of noob asks and then says I know? Improper groveling I say... If you look at the function again, you can tell that strlen() already computes the number of characters in your string for you. Actually, that would be your char pointer there Dagoth Nereviar, place your char or char array variable or whatever with characters you want to manipulate in that something. But of course, you already knew that. In case you don't... Hehe, sorry, I wasn't saying I definatly knew, I was just guessing...And I told you, I am a noob Thanks, I don't have time right now (other college work >.<) but I should have looked over it/tried it by tomorrow Thanks, from the big noob who thinks he knows it all |
|
|
|
Jul 6 2007, 06:45 PM
Post
#9
|
|
|
Member [Level 1] ![]() ![]() ![]() ![]() Group: Members Posts: 66 Joined: 23-June 07 Member No.: 45,329 |
what about this function ?
apstring n2; what does apstring do ?? please explain ? |