String concatenation: Difference between revisions
Content added Content deleted
(Created task with BASIC and Java) |
(added c++) |
||
Line 7: | Line 7: | ||
s2$ = s$ + " literal" |
s2$ = s$ + " literal" |
||
print s2$</qbasic> |
print s2$</qbasic> |
||
Output: |
|||
<pre>hello literal |
|||
hello literal</pre> |
|||
=={{header|C++}}== |
|||
<cpp>#include <string> |
|||
#include <iostream> |
|||
int main() { |
|||
std::string s = "hello"; |
|||
std::cout << s << " literal" << std::endl; |
|||
std::string s2 = s + " literal"; |
|||
std::cout << s2 << std::endl; |
|||
return 0; |
|||
}</cpp> |
|||
Output: |
Output: |
||
<pre>hello literal |
<pre>hello literal |
Revision as of 21:56, 17 December 2008
String concatenation
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
Set a string variable equal to any text value. Print it to the console concatenated with a string literal. Create a new string variable whose value is the other variable concatenated with a string literal. Print this new variable.
BASIC
<qbasic>s$ = "hello" print s$;" literal" 'or s$ + " literal" s2$ = s$ + " literal" print s2$</qbasic> Output:
hello literal hello literal
C++
<cpp>#include <string>
- include <iostream>
int main() {
std::string s = "hello"; std::cout << s << " literal" << std::endl; std::string s2 = s + " literal"; std::cout << s2 << std::endl; return 0;
}</cpp> Output:
hello literal hello literal
Java
<java>public class Str{
public static void main(String[] args){ String s = "hello"; System.out.println(s + " literal"); String s2 = s + " literal"; System.out.println(s2); }
}</java> Output:
hello literal hello literal