我收到以下代码的上述错误。请帮我解决我做错了什么。此代码具有嵌套结构。现在它会根据用户的输入为生成结构生成名称。
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <limits>
#include <stdio.h>
#include <sstream>
using namespace std;
using std::stringstream;
struct rootset {
double totSize;
const char *rStrtPtr;
const char *rEndPtr;
struct generations {
double totSize;
const char *genStrtPtr;
const char *genEndPtr;
int numOfGen;
int genName;
struct object {
double objSize;
const char *objStrtPtr;
const char *objEndPtr;
string id;
char markBit;
char objPtr;
struct freeList {
double freeSpace;
int flNumb;
};
};
} generation;
};
int main()
{
int gen =0;
cin >> gen;
rootset* pRootSet = (rootset*)malloc(1200);
for( i=0; i<gen; i++) {
stringstream out;
out << i;
string s = out.str();
string foo = "generation";
pRootSet->generation.genName = foo.append(s); /*Error is here*/
cout<<"foo: "<<foo<<endl;
}
}
我正在尝试打印这个答案:
4
foo: generation0
foo: generation1
foo: generation2
foo: generation3