回答編集履歴

4

訂正

2019/02/24 11:24

投稿

cateye
cateye

スコア6851

test CHANGED
@@ -88,14 +88,6 @@
88
88
 
89
89
  123456789abcdef
90
90
 
91
- usr ~/Project/test % c++ --version
92
-
93
- clang version 8.0.0 (trunk 350063)
94
-
95
- Target: x86_64-unknown-linux-gnu
96
-
97
- Thread model: posix
98
-
99
91
  usr ~/Project/test %
100
92
 
101
93
 

3

ソース修正

2019/02/24 11:24

投稿

cateye
cateye

スコア6851

test CHANGED
@@ -44,11 +44,15 @@
44
44
 
45
45
  #include <string>
46
46
 
47
+ #include <vector>
48
+
47
49
 
48
50
 
49
51
  int main(void)
50
52
 
51
53
  {
54
+
55
+ std::vector<std::string> sv;
52
56
 
53
57
  std::string s;
54
58
 
@@ -58,7 +62,11 @@
58
62
 
59
63
 
60
64
 
65
+ sv.push_back(s);
66
+
67
+
68
+
61
- std::cout << s << std::endl;
69
+ std::cout << sv[0] << std::endl;
62
70
 
63
71
 
64
72
 

2

追記

2019/02/24 09:59

投稿

cateye
cateye

スコア6851

test CHANGED
@@ -29,3 +29,87 @@
29
29
  で、std::cinはvectorに直接データを書き込めません。
30
30
 
31
31
  なので、一旦std::stringに読み込んでpush_back()で挿入。
32
+
33
+ [追記]
34
+
35
+ ちなみにテスト用のソース
36
+
37
+ ```cpp
38
+
39
+ usr ~/Project/test % cat tst.cpp
40
+
41
+
42
+
43
+ #include <iostream>
44
+
45
+ #include <string>
46
+
47
+
48
+
49
+ int main(void)
50
+
51
+ {
52
+
53
+ std::string s;
54
+
55
+
56
+
57
+ std::cin >> s ;
58
+
59
+
60
+
61
+ std::cout << s << std::endl;
62
+
63
+
64
+
65
+ return 0;
66
+
67
+ }
68
+
69
+
70
+
71
+ ```
72
+
73
+ コンパイルと結果です。
74
+
75
+ usr ~/Project/test % c++ tst.cpp
76
+
77
+ usr ~/Project/test % ./a.out
78
+
79
+ 123456789abcdef
80
+
81
+ 123456789abcdef
82
+
83
+ usr ~/Project/test % c++ --version
84
+
85
+ clang version 8.0.0 (trunk 350063)
86
+
87
+ Target: x86_64-unknown-linux-gnu
88
+
89
+ Thread model: posix
90
+
91
+ usr ~/Project/test %
92
+
93
+
94
+
95
+ コンパイラとオプションです。
96
+
97
+ ```text
98
+
99
+ alias c++ /xxxxx/bin/clang++ -Wno-c++98-compat -Wno-padded -pipe -std=c++17 -Weverything -Ofast
100
+
101
+ usr ~/Project/test % c++ --version
102
+
103
+ clang version 8.0.0 (trunk 350063)
104
+
105
+ Target: x86_64-unknown-linux-gnu
106
+
107
+ Thread model: posix
108
+
109
+ InstalledDir: /xxxxx/bin
110
+
111
+ usr ~/Project/test %
112
+
113
+
114
+
115
+ ```

1

誤記修正

2019/02/24 09:42

投稿

cateye
cateye

スコア6851

test CHANGED
@@ -28,4 +28,4 @@
28
28
 
29
29
  で、std::cinはvectorに直接データを書き込めません。
30
30
 
31
- なので、一旦string読み込んでoush_back()で挿入。
31
+ なので、一旦std::string読み込んでpush_back()で挿入。