C++ 如何将字符串存储到数组中?

C++ 如何将字符串存储到数组中?,c++,C++,我想将这个字符串存储到数组中 空间=0 A、 A=1 B、 B=2 C,C=3 。 . Z、 Z=26 string myArray[26] = { "A", "B", "C", "D",”E”,”F”,”G”,”H”,”I”,”J”,”K”,”L”,”M”,”N”,”O”,”P”, ”Q”,”R”,”S”,T”,”U”,”V”,W”,X”,”Y”, ”z” }; for (int i = 0; i < myArray; i++) {

我想将这个字符串存储到数组中

空间=0

A、 A=1

B、 B=2

C,C=3

。 .

Z、 Z=26

 string myArray[26] =
       { "A", "B", "C", "D",”E”,”F”,”G”,”H”,”I”,”J”,”K”,”L”,”M”,”N”,”O”,”P”,
        ”Q”,”R”,”S”,T”,”U”,”V”,W”,X”,”Y”, ”z” };

 for (int i = 0; i < myArray; i++)
 {                 
    myArray[] = myArray[i]  
    cerr << myArray[i] << endl << endl;                  
 }
字符串myArray[26]=
{“A”、“B”、“C”、“D”、“E”、“F”、“G”、“H”、“I”、“J”、“K”、“L”、“M”、“N”、“O”、“P”,
“Q”、“R”、“S”、“T”、“U”、“V”、“W”、“X”、“Y”、“z”};
for(int i=0;icerr您得到的是字符串数组,而不是字符数组。
字符串
是字符容器,可以容纳多个字符。您的任务可以使用一个或两个字符串来解决,具体取决于您的设计首选项(见下文)

A、 A=1

B、 B=2

每个位置放置两个字符。但是,
string
s在一个索引中不能包含多个字符。如果需要大写和小写字符占据同一位置,则需要创建两个字符串或两个位置

以下是第一种方法(两个字符串):

string upper=“ABCDEF…”;
字符串下限=“abcdef…”;
int pos=…;//所需位置

cout‘这是获得每个字符的数字的方法吗?’简言之:NO.“…这个字符串…”请问是哪一个?我不想粗鲁,但我不能…停止…哦,不…空格=0a,A=1b,B=2c,C=3..Z,Z=26@EdHeal当然不是:-)至少,赋值后缺少一个分号。你所说的int-pos是什么意思?在序列中写一个数字是什么?@aigment
pos
是序列中的数字当
pos
为零时,得到一个空格;当
pos
为一时,得到一个
'a'
'a'
,依此类推。
string upper = " ABCDEF...";
string lower = " abcdef...";
int pos = ...; // The desired position
cout << upper[pos] << endl;
cout << lower[pos] << endl;
string pairs = "  AaBbCcDdEeFf...";
int pos = ...; // The desired position
cout << pairs[2*pos] << endl;   // Upper
cout << pairs[2*pos+1] << endl; // Lower