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

  • SEARCH
  • Home
  • 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 6001147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:47:39+00:00 2026-05-23T00:47:39+00:00

I am trying to import data from a file in my project but I

  • 0

I am trying to import data from a file in my project but I am having trouble finding EOF. Firstly, I used the EOF function as a condition but I after reading this, I tried changed the code but still it is giving same error. Please help me out.
Thanks

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class Rooms;
class Guest;
class MeetingRoomGuest;
Rooms* r_ptr[999];
int r_count=0;

ofstream infile("new.txt",ofstream::binary);
while(infile.read((char *)(&r_ptr[r_count]),sizeof(Rooms)))
{   
    r_count++;
}
infile.close(); 
int main ()
{
    // some code here
    return 0;
}

ERROR:

error C2059: syntax error : ‘while’

UPDATE:
Please let me know if this is a better implementation?Thanks

int main()
{
    r_ptr[r_count]= new Rooms;
    while(infile.read((&r_ptr[r_count]),sizeof(Rooms)))
    {   
        r_ptr[++r_count]= new Rooms;
        r_count++;
    }
    infile.close(); 
    //some code here
}

I am still getting an error,

ERROR:

error C2039: ‘read’ : is not a member of ‘std::basic_ofstream<_Elem,_Traits>’

UPDATE:
Thanks alot. The code has finally fixed,here is the final implementation,

int main()
{
    r_ptr[r_count]= new Rooms;
    while(infile.read((char *)(&r_ptr[r_count]),sizeof(Rooms)))
    {   
        r_count++;
        r_ptr[r_count]= new Rooms;

    }
    infile.close(); 
    // some work
}
  • 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-23T00:47:39+00:00Added an answer on May 23, 2026 at 12:47 am

    It seems you have one or two syntax problems:

    1. you’ve got code outside of a function or main (the while and infile commands) they need to be put into main or a function.

    2. your second while needs a do (do{....}while(1), also it runs forever

    3. All your variables are defined outside of main. This makes them global variables, a thing to be avoided as much as possible. They should be moved inside main as well

    4. ofstream are used to Output to a file, you want a ifstream to get Input from a file

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I’m trying to import fixed width data from text file into SQL Server Express
I am trying to import data from a CSV file to a SQL Server
I am trying to import data from a dump file created by Oracle 10g
I am trying to import data from a utf-8 encoded flat file into SQL
In this situation I am trying to perform a data import from an XML
I am trying to import an excel file into a data table using GemBox
I am trying to import a csv file to insert data into an existing
I'm trying to write an import function for getting data out of an excel
I am trying to import the contact list from gmail using libgmailer.php but I
I am trying to get data pulled from a SQLite file, i have created

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.