我正在尝试将本地函数中的for循环中的整数存储到全局数组中,这可能吗?我现在拥有的是:
int num[] = {0};
int Num[] = {0};
void convert(string text, string key)
{
for (int i = 0; i < text.length(); i++)
{
char x = text.at(i);
num[i] += int(x) - 97;
cout << num[i] << endl;
}
for (int i = 0; i < key.length(); i++)
{
char y = key.at(i);
Num[i] += int(y) - 97;
cout << Num[i] << endl;
}}
如何将for循环的输出存储到全局数组?
答案 0 :(得分:0)
首先,您要初始化大小为1的数组,并获得与使用向量(动态数组)而不是普通数组所需的字符串相同的大小。然后你将在每个向量上使用resize方法并将每个字符串的长度放在那里,以具有相同的大小。 (谷歌:矢量c ++;了解这个很棒的课程,因为你将在不久的将来更多地使用它)
[
"113": SellerApp.Product(name: "aaaa", id: "113", images: [SellerApp.ProductImage(myId: "996", url: http://myApp.com/public/uploads/products/123_113_1_image_123456789, isDefault: true)], theRate: "234", quantity: "17", sku: "Hdjsu", prdCateg: "tr123", prodDescr: "Gdhd", mrp: "520"),
"101": SellerApp.Product(name: "dfg", id: "101", images: [SellerApp.ProductImage(myId: "982", url: http://myApp.com/public/uploads/products/563_101_1_image_1011121314, isDefault: true)], theRate: "123", quantity: "7", sku: "345", prdCateg: "tr123", prodDescr: "Test", mrp: "234")
]