0

im getting the above error for the following code. Please help me with what i am doing wrong. This code has nested structures. For now it generates name for the generation structure based on the input given by the user.

#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;
  }
}

i am trying to print this answer:

4
foo: generation0
foo: generation1
foo: generation2
foo: generation3

1 Answer 1

1

generation.genName is of INT type while you want to pass a string value without any conversion, that's why it gives it an error. Solution: do the conversion before.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.