0

I'm making a student record system for an assignment. When trying to run the program I get the error:

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

It's coming from the stringstream key = student[j].getLastName line. Not sure what is 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 i = 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 the menu and asks for user input
        cout << "What would you like to 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 i = 0; i < 50; i++){ //Full print loop
                cout << student[i] << endl;
            }
            cout << endl;
            keepGoing = true;
        }
        //Just first and last name
        else if(choice == 2){
            cout << "First Last" << endl;
            for(int i = 0; i < 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 i = j - 1;
                while(i > 0 && student[i].getLastName > key){
                    student[i+1] = student[i];
                    i = i - 1;
                }
                Student[i + 1] = key;
            }

            for j = 1 to A.length
            key = A[j]
            i = j - 1
            while i > 0 and A[i] > key
            A[i + 1] = A[i]
            i = i - 1
            A[i + 1] = key

            keepGoing = true;
        }
        //quit
        else if(choice == 4){
    cout << "Goodbye!" << endl;
            keepGoing = false;
        }
    }
        return 0;
}
3
  • getLastName seems to be a function, which supposedly return something. Aren't you supposed to call this function to get the returned value? Commented Oct 22, 2015 at 13:37
  • Can you post your student class? Commented Oct 22, 2015 at 13:37
  • 2
    Oh, and after you fix the first error, you will get many more errors. C++ isn't BASIC you know? Please try to actually read the error messages you get, and look at the lines they point to, do the code on those lines look like they should? Commented Oct 22, 2015 at 13:38

1 Answer 1

1

When you do stringstream key = student[j].getLastName, you try to create a new stringstream object copying from getLastName. Now, getLastName is probably a member function, so the compiler doesn't know how to build a stringstream from it.

You probably wanted to initialize a stringstream with the value returned from your member function, so:

stringstream key(student[j].getLastName());
Sign up to request clarification or add additional context in comments.

2 Comments

Paolo your solution worked but now I am getting an erro in my while loop for not match for operator> in (student + ((unsigned int) (((unsigned int)i) * 108u)))->Student::getLastName > key. I'm a little lost with this whole thing. I'm quite new with C++
@Anthony Pretty much the same thing. getLastName is a (member) function. When you do student[i].getLastName > key, you really don't want to know whether a function is greater than a string; you want to know if the value returned by your function it is! So, again, add () to getLastName

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.