我想编写一个程序,根据加权平均数计算班级的最终成绩,并且我正在提示用户输入每个类别的名称(例如“家庭作业”,“测验”等) )。我已经设置了询问用户他们有多少类别,然后单独询问他们每一个,然后将每个类别名称作为字符串保存到数组元素中。我知道它可能更容易使用矢量类,但我希望尽可能以这种方式来完成。将一个字符串赋值给一个数组的元素?
#include <cmath>
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <string>
using namespace std;
int main()
{
cout << "How many grade categories are there for this class? ";
cin >> categories;
int * categorynames = new int[categories];
for (int i(0); i < categories; i++)
{
string text;
cout << "Name of category: ";
getline(cin, text);
categorynames[i] = text;
}
当我编译时,我得到一个错误“不能将std :: string转换为int在赋值。”
任何人都可以帮忙吗?