質問編集履歴

2

文字列という事で修正

2022/08/25 02:54

投稿

ma2hiro
ma2hiro

スコア157

test CHANGED
File without changes
test CHANGED
@@ -18,7 +18,7 @@
18
18
  cCust2 customer[100];
19
19
 
20
20
  strcpy((char*)customer[0].sOrder, "ABC");
21
- // customer[0].sOrder = "ABC";
21
+ // customer[0].sOrder[0] = "ABC";
22
22
  if (customer[0].sOrder[0].compare('A')) {
23
23
  cout << "OK" << endl;
24
24
  }

1

クラスで困っている事修正

2022/08/25 02:22

投稿

ma2hiro
ma2hiro

スコア157

test CHANGED
@@ -1 +1 @@
1
- Sringの一文字目が’A'かどうかの処理をお伺いしてよろしいでしょうか?
1
+ 【修正】Sringの一文字目が’A'かどうかの処理をお伺いしてよろしいでしょうか?
test CHANGED
@@ -9,23 +9,25 @@
9
9
  ### 発生している問題・エラーメッセージ
10
10
 
11
11
  ```
12
- #include <iostream>
13
- #include <string>
12
+ class cCust2 {
13
+ public:
14
- #include <vector>
14
+ string sOrder[20];
15
+ };
15
16
 
16
- using namespace std;
17
- int main() {
17
+ int main__() {
18
+ cCust2 customer[100];
19
+
18
- string sTest="ABC";
20
+ strcpy((char*)customer[0].sOrder, "ABC");
19
- const string sTest0 = sTest[0];
21
+ // customer[0].sOrder = "ABC";
20
- if (strcmp(sTest0, 'A')) {
22
+ if (customer[0].sOrder[0].compare('A')) {
21
- cout << OK << endl;
23
+ cout << "OK" << endl;
22
24
  }
23
25
  }
24
26
  ```
25
27
  と実装したが
26
28
  ```
27
29
  重大度レベル コード 説明 プロジェクト ファイル 行 抑制状態
28
- エラー (アクティブ) E0415 "char" から "std::basic_string<char, std::char_traits<char>, std::allocator<char>>" に変換するため適切なコンストラク存在しません
30
+ エラー (アクティブ) E0304 オーバーロードされた関数 "std::basic_string<_Elem, _Traits, _Alloc>::compare [代入_Elem=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>]" のンスタンス引数リストと一致しません ConsoleApplication2
29
31
  ```
30
32
 
31
33
  上記 関数の使用方法が違うのか