Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6698575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:35:39+00:00 2026-05-26T06:35:39+00:00

Hello Users of Stack Overflow! I’m having an issue with a program I’m attempting

  • 0

Hello Users of Stack Overflow!

I’m having an issue with a program I’m attempting to write in C++. Every time I compile my code I get the following Errors:

FCS2Phase.cpp: In function `int main(int, char**)':
FCS2Phase.cpp:47:15: error: request for member `open' in `userfile', which is of non-class type `std::ifstream()'
FCS2Phase.cpp:48:22: error: request for member `eof' in `userfile', which is of non-class type `std::ifstream()'
FCS2Phase.cpp:50:39: error: cannot convert `std::ifstream (*)()' to `char**' for argument `1' to `ssize_t getline(char**, size_t*, FILE*)'
FCS2Phase.cpp:52:49: error: cannot convert `std::ifstream (*)()' to `char**' for argument `1' to `ssize_t getline(char**, size_t*, FILE*)'
FCS2Phase.cpp:54:14: error: request for member `close' in `userfile', which is of non-class type `std::ifstream()'

Being so new to C++ I’m not too sure what this error is trying to tell me is incorrect with my use of ifstream. I’m sure this has to be something stupidly simple but i cannot figure it out 🙁 Ive tried some desperate things like dereferencing userFile calling it as (userFile*).open and also userGFile->open. both result in the same errors.

The lines of code effected by this is as follows:

int count = 0;
userfile.open(fileName.c_str(), ios::in | ios::binary);
while (!userfile.eof()) {
    if (count < arrSize)
        getline(userfile, a[count]);
    else if (count - arrSize < arrSize)
        getline(userfile, b[count - arrSize]);
}
userfile.close();

The whole program is as follows:

/* 
 * File:   FCS2Phase.cpp
 * Author: Mark
 *
 * Created on October 17, 2011, 11:28 AM
 */

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <time.h>
#include <string>

using namespace std;

void randInput(int size, string fileName);

/*
 * 
 */
int main(int argc, char** argv) {

    string fileName;
    char randYN;
    int arrSize;
    cout << "(This program assumes file is in program root directory and arrays are equal size)";
    cout << "\nPlease insert the file name: ";
    getline(cin, fileName);

    ifstream userfile();

    cout << "How many numbers are stored in the arrays?: ";
    cin >> arrSize;

    double a[arrSize];
    double b[arrSize];

    cout << "Create Randomized File? (Y/N): ";
    cin >> randYN;

    if (toupper(randYN) == 'Y')
        randInput(arrSize * 2, fileName);



    int count = 0;
    userfile.open(fileName.c_str(), ios::in | ios::binary);
    while (!userfile.eof()) {
        if (count < arrSize)
            getline(userfile, a[count]);
        else if (count - arrSize < arrSize)
            getline(userfile, b[count - arrSize]);
    }
    userfile.close();



    cout << "The values inputted were: " << "\n\tArray #1: ";
    for (int i = 0; i < arrSize; i++) {
        cout << a[i] << "\t";
    }
    cout << "\n\tArray #2: ";
    for (int i = 0; i < arrSize; i++) {
        cout << b[i] << "\t";
    }

    return 0;
}

void randInput(int size, string fileName) {
    const double MIN = 0;
    const double MAX = 100;
    double num;
    ofstream file(fileName.c_str());
    if (file.is_open()) {
        for (int i = 0; i < size; i++) {
            srandom(time(NULL));
            num = (double) rand() / RAND_MAX;
            file << MIN + num * (MAX - MIN) << "\n";
        }
        file.close();
    }
}

Thank you for any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:35:39+00:00Added an answer on May 26, 2026 at 6:35 am

    The following line should be

     ifstream userfile;
    

    instead of

     ifstream userfile();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to get my first hello world rails example going using the rails'
Hello Stack Overflow Experts, i have need of your expertice: I am trying to
Hello good Stack Overflow people, I do have a business problem and would like
Hello Stack Overflow i hope you are well today; I have a form that
Hello stack overflow I need help with this problem. Ok, I have a flat
In this Stack Overflow answer $('#user_button').toggle(function () { $(".hello").addClass("active"); }, function () { $(".hello").removeClass("active");
Hello everyone this is my first post on stack overflow.com I am trying to
This is the first time i'm asking a question here at stack overflow so
I'm experimenting with internationalization by making a Hello World program that uses properties files
Hello fellow StackOverflow users (or Stackoverflowers ?): I'm learning-by-coding WPF. I read several articles/saw

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.