|
-
Sep 29th, 2002, 06:04 AM
#1
Thread Starter
Fanatic Member
Newbie string addition
I know this will be easy, just that i am new to the string side of C++ (i can understand the maths parts as it's similar to VB, which i am better at)
I just am wondering the most efficient way to do the equivalent of this:
Dim a$, b$
a$ = "he"
b$ = "llo"
a$ = a$ + b$
Print a$
sql_lall 
-
Sep 29th, 2002, 08:04 AM
#2
transcendental analytic
you concentarte c strings with strcat, the string class should have a overloaded operator +
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Sep 29th, 2002, 10:53 AM
#3
Monday Morning Lunatic
Re: Newbie string addition
Originally posted by sql_lall
I know this will be easy, just that i am new to the string side of C++ (i can understand the maths parts as it's similar to VB, which i am better at)
I just am wondering the most efficient way to do the equivalent of this:
Dim a$, b$
a$ = "he"
b$ = "llo"
a$ = a$ + b$
Print a$
Code:
string a("he");
string b("llo");
a += b;
cout << a << endl;
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 30th, 2002, 05:14 AM
#4
Thread Starter
Fanatic Member
thanks
I think i'll use the strcat method. However, i was unaware that you could declare strings like that and use them. What versions of C++ can you do that in??
sql_lall 
-
Sep 30th, 2002, 07:16 AM
#5
Monday Morning Lunatic
Um, you can do it in C++, C++, or C++.
strcat is for C-style strings declared as pointers/arrays. C++ is slightly more intelligent about it.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 30th, 2002, 12:40 PM
#6
For the string class you need these two lines at the top of your app:
#include <string>
using namespace std;
The include directive imports the file "string" into your app (which is where the string class is declared). Don't worry about the other line for now, wait until you learn about namespaces. It's not very high priority. Just remember you need it everytime you include any headers from the C++ standard library.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 5th, 2002, 06:04 AM
#7
Thread Starter
Fanatic Member
One slight error
Ok, i tried the using namespace std; thing, but it didn't work.
Just a question, should it matter whether the i #included <string> or <string.h>, of for that matter is there any difference between <[headername]> and <[headername].h>??
sql_lall 
-
Oct 5th, 2002, 07:26 AM
#8
Frenzied Member
If there is a .h at the end, and there is another ehader without it, the one without is newer, and should be used.
Z.
-
Oct 6th, 2002, 04:54 AM
#9
Thread Starter
Fanatic Member
OK
Yeah, i had to use no .h
It solved the problem, but i couldn't cout<< the strings.
Any suggestions. ( i just tried the code posted before, with the necessary headings, but the cout line came up with an error)
sql_lall 
-
Oct 6th, 2002, 05:15 AM
#10
Monday Morning Lunatic
You need <iostream>, not <iostream.h> or it won't work properly.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 7th, 2002, 04:57 AM
#11
Thread Starter
Fanatic Member
-
Oct 7th, 2002, 06:14 AM
#12
Monday Morning Lunatic
It starts with the cool guy getting an idea 
It was made by Bloodeye (I think) who I haven't seen around here for ages now...
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|