Computing.Net > Forums > Programming > String connection in Unix/c++

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

String connection in Unix/c++

Reply to Message Icon

Name: LaoMa
Date: September 18, 2002 at 19:27:40 Pacific
OS: Unix/Linux
CPU/Ram: 256M
Comment:

Hi,I wonder how to connect 2 strings in c++ under Unix?
I tried strcat,and the code got stuck(no compiling error,though).
This is what I'm doing:
char* s1="bin";
char* s2="***";
...
cout<simply doesn't work! The execution stops at the strcat.



Sponsored Link
Ads by Google

Response Number 1
Name: cup
Date: September 19, 2002 at 14:18:58 Pacific
Reply:

You need to allocate space if you are going to do it the C way. There is a string type in C++.

#include // note not string.h
#include
using namespace std;
main ()
{
string s1 = "bin ";
string s2 = "liner";

string s3 = s1 + s2;

cout << s3 << endl;

return 0;
}

Should give you "bin liner"


0

Response Number 2
Name: cup
Date: September 19, 2002 at 14:19:58 Pacific
Reply:

The includes were

string
iostream

There is a problem with angle brackets in this forum.


0

Response Number 3
Name: LaoMa
Date: September 19, 2002 at 19:57:01 Pacific
Reply:

Got it.Thanks.
Sorry another basic question:
what's the essential difference between string and char* or char[]?
For example,if I define char[20] path,then assign "/bin/" to it,the compiler complains that the constant char[5] doesn't match the string.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


how do u do a beep sound ... Test Serial Port in VB6



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: String connection in Unix/c++

How to use string array in C++? www.computing.net/answers/programming/how-to-use-string-array-in-c/9478.html

dsn less connection in java www.computing.net/answers/programming/dsn-less-connection-in-java/10322.html

Unix C in Windows enviroment www.computing.net/answers/programming/unix-c-in-windows-enviroment/1173.html