Here we will learn how to write a program to Concatenate strings.
CONCATENATION OF TWO STRINGS USING C++ PROGRAM
# include < iostream> # include < string > using namespace std; int main() { char str1[50], str2 [35]; cout << "Enter string str1;"; cin >> str1; cout << "Enter string str2:"; cin >> str2; strcat(str1,str2); cout << "strcat (str1, str2 ) : "<< str1; system("pause"); return 0; }
- C++ Simple Programs And Examples
- C++ – Hello World Program
- C++ – Simple calculator
- C++ – Even and Odd
- C++ – Swap two numbers
- C++ – Prime Number
- C++ – Find Perfect Number
- C++ – Factorial of Number
- C++ – Fibonacci Series
- C++ – Human Resource Management Program
- C++ – Calculate number of characters, words, sentences
- C++ – Subtract two Strings
- C++ – Processing of the Students structure
- C++ – Program with Matrices
- C++ – Calculate Equation
- C++ – Arrange Numbers in Ascending order
- C++ – Check Armstrong Number
- C++ – HCF and LCM
- C++ – Square Root of a Number
- C++ – Cube Root of a Number
- C++ – ASCII Code for Characters and numbers
- C++ – Check Palindrome Number
- C++ – Bubble sort
- C++ – Random Number Generator
- C++ – Sum of ODD Numbers in the Given Range
- C++ – Display current date and time
- Formula Based Programs
- C++ – Leap Year
- C++ – Surface Area and volume of cone
- C++ – Solve Quadratic equation
- String Based Programs
- C++ – String into Upper case or lower case
- C++ – Concatenate Strings
- Array Based Programs
- C++ – Program with Matrices
- Print Any Patterns
- C++ – Print 5 rows of 10 Stars (*)
- C++ – Half Pyramid of Stars (*)
- C++ – Half Pyramid of numbers
- C++ – Print Triangle of Stars
- C++ – Display Reverse pyramid.
- C++ – Print Alphabet Pattern
- C++ – Diamond of Star
- C++ – Pascal Triangle
- C++ – Floyd Triangle
- C++ Conversion
- C++ – Convert decimal to Hexadecimal
- C++ – Decimal to Binary
- C++ Sorting algorithms & Techniques
- C++ – Bubble Sort
- C++ – Insertion Sort
- C++ – Selection Sort
- C++ – Merge Sort
- C++ – Quick Sort
- C++ Handling Files
- C++ – How to get Current Directory in Linux/Windows
- C++ – How Create a Text File and Write in It
I have a heavy fight with string Constant in c/c++, and I would like to know the cleanest and most elegant way to achieve the goal.
A given string may be used in more than one place in your program. It is good programming praxis to define a string constant in one place and then use it ever where you need. Hence in Java I would say:
public/private static final String MY_STRING_REF = “whatever I need”;
It’s obvious, that if I must change the String to say “whatever I need now!”, I change it exactly in one place and with the next compiler run the new string is available where ever it was referenced. Beside the string value is stored exactly once in the program space.
I would like to apply this praxis to c++ too. But if your c++ programs use old structures from c, things turn ugly!
Example:
JavaVMOption* options = new JavaVMOption[1]; // JVM invocation options
options[0].optionString = (char *)CLASSPATH;
Yes, this is old JNI interface to access OS-services from Java through c++
I have found a kind of declaration without complains from the compiler as:
const char * CLASSPATH = “-Djava.class.path=.:./xx”;
This works. But I don’t like the type cast and I would be happy to know a more elegant way to achieve it. Maybe this could be a good example for your tutorial site.