Ongoing/String

[C++ C# Python Java] String Concatenation

More Code 2019. 5. 21. 11:09


// [C++] String Concatenation

// VC : suppress error messages about obsolete & deprecated functions
#pragma warning(disable : 4996)
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS_GLOBALS

#include <iostream>
#include <string>

using namespace std;

int main()
{
// string text0 = "Hello" + "World"; // error
string text1 = "Hello" "World";
cout << text1 << endl;

string word1 = "Hello";
string word2 = word1 + "World";
cout << word2 << endl;

char text2[11];
strcpy(text2, "Hello");
strcat(text2, "World");
printf(text2);
}




// [C#] String Concatenation

using System;

namespace Sharp1
{
class Program
{
static void Main(string[] args)
{
string text = "Hello" + "World";
Console.WriteLine(text);
}
}
}




# [Python] String Concatenation


def main():
text = "Hello" + "World"
print(text)


if __name__ == '__main__':
main()




// [Java] String Concatenation

package package1;

public class Program {
public static void main(String[] args) {
String text = "Hello" + "World";
System.out.println(text);
}
}