"String array"의 두 판 사이의 차이

15번째 줄: 15번째 줄:
using namespace std;
using namespace std;
int main() {
int main() {
     char weekDays[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
     char fruits[3][10] = {"apple", "banana", "cranberry"};
     for(int i=0; i<7; i++) cout << weekDays[i] << " ";
    for(int i=0; i<3; i++) cout << fruits[i] << " ";
     // Sun Mon Tue Wed Thu Fri Sat
    // apple banana cranberry
}
</source>
<source lang='cpp'>
#include <iostream>
using namespace std;
int main() {
    string fruits[3] = {"apple", "banana", "cranberry"};
    for(int i=0; i<3; i++) cout << fruits[i] << " ";
    // apple banana cranberry
}
</source>
<source lang='cpp'>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    vector<string> fruits;
    fruits.push_back("apple");
    fruits.push_back("banana");
    fruits.push_back("cranberry");
     for(int i=0; i<fruits.size(); i++) cout << fruits[i] << " ";
     // apple banana cranberry
}
}
</source>
</source>

2019년 1월 25일 (금) 20:05 판


1 ActionScript

var weekDays:Array = new Array( "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" );

2 C++

#include <iostream>
using namespace std;
int main() {
    char fruits[3][10] = {"apple", "banana", "cranberry"};
    for(int i=0; i<3; i++) cout << fruits[i] << " ";
    // apple banana cranberry 
}
#include <iostream>
using namespace std;
int main() {
    string fruits[3] = {"apple", "banana", "cranberry"};
    for(int i=0; i<3; i++) cout << fruits[i] << " ";
    // apple banana cranberry 
}
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    vector<string> fruits;
    fruits.push_back("apple");
    fruits.push_back("banana");
    fruits.push_back("cranberry");
    for(int i=0; i<fruits.size(); i++) cout << fruits[i] << " ";
    // apple banana cranberry 
}

3 C#

string[] stringArray = new string[6];

string[] weekDays = new string[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };

string[] weekDays2 = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };

4 Java

String[] weekDays = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
System.out.println(Arrays.toString(weekDays));
// [Sun, Mon, Tue, Wed, Thu, Fri, Sat]

5 Objective-C

NSArray *weekDays = [NSArray arrayWithObjects:@"Sun", @"Mon", @"Tue", @"Wed", @"Thu", @"Fri", @"Sat", nil];

6 Perl

@weekDays = ( "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" );

$weekDays_ref = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ];

7 PHP

$weekDays = array( "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" );

8 Python

weekDays = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ]

9 Ruby

fruits = ['apple', 'banana']
print fruits
# ["apple", "banana"]

10 See also