C++ error in sort function -


i'm making student record system assignment. when trying run program error:

"error: conversion '' non-scalar type 'std::stringstream' requested"

it's coming stringstream key = student[j].getlastname line. not sure wrong.

#include <sstream> #include <iostream> #include <fstream> #include "date.h" #include "address.h" #include "student.h"   using namespace std;  int main(){      string line;     ifstream inputfile("studentdata.txt");     bool keepgoing = true;     student *student = new student[50];     int = 0;     while(!inputfile.eof()){         getline(inputfile, line);         student[i].setinfo(line);         i++;     }     int choice;     cout << "a heap of students";     while(keepgoing){ //this while loop creates menu , asks user input         cout << "what do?" << endl;         cout << "1. print full report." << endl;         cout << "2. print simple report." << endl;         cout << "3. sort records." << endl;         cout << "4. quit" << endl;         cin >> choice;          //prints full student report         if(choice == 1){             for(int = 0; < 50; i++){ //full print loop                 cout << student[i] << endl;             }             cout << endl;             keepgoing = true;         }         //just first , last name         else if(choice == 2){             cout << "first last" << endl;             for(int = 0; < 50; i++){ //simple print loop             cout << student[i].getfirstname() << " " << student[i].getlastname() << endl;             }             cout << endl; //formatting             keepgoing = true;         }         //sort function         else if(choice == 3){             for(int j = 1; j < 50; j++){                 stringstream key = student[j].getlastname;                 int = j - 1;                 while(i > 0 && student[i].getlastname > key){                     student[i+1] = student[i];                     = - 1;                 }                 student[i + 1] = key;             }              j = 1 a.length             key = a[j]             = j - 1             while > 0 , a[i] > key             a[i + 1] = a[i]             = - 1             a[i + 1] = key              keepgoing = true;         }         //quit         else if(choice == 4){     cout << "goodbye!" << endl;             keepgoing = false;         }     }         return 0; } 

when stringstream key = student[j].getlastname, try create new stringstream object copying getlastname. now, getlastname member function, compiler doesn't know how build stringstream it.

you wanted initialize stringstream value returned member function, so:

stringstream key(student[j].getlastname()); 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -