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 749319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:25:15+00:00 2026-05-14T14:25:15+00:00

this is an implementation of length indicator field but it hang and i think

  • 0

this is an implementation of length indicator field
but it hang and i think stuck at a loop and don’t show any thing.

// readx22.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "iostream"
#include "fstream"
#include "stdio.h"
using namespace std;


class Student
{
public:
 string id;
 size_t id_len;
 string first_name;
 size_t first_len;
 string last_name;
 size_t last_len;
 string phone;
 size_t phone_len;
 string grade;
 size_t grade_len;
 void read(fstream &ven);
 void print();
};
void Student::read(fstream &ven)
{
 size_t cnt;
 ven >> cnt;
 id_len=cnt;
    id.reserve( cnt );
    while ( -- cnt ) {
        id.push_back( ven.get() );
    }

 ven >> cnt;
 first_len=cnt;
    first_name.reserve( cnt );
    while ( -- cnt ) {
        first_name.push_back( ven.get() );
    }

 ven >> cnt;
 last_len=cnt;
    last_name.reserve( cnt );
    while ( -- cnt ) {
        last_name.push_back( ven.get() );
    }

 ven >> cnt;
 phone_len=cnt;
    phone.reserve( cnt );
    while ( -- cnt ) {
        phone.push_back( ven.get() );
    }

 ven >> cnt;
 grade_len=cnt;
    grade.reserve( cnt );
    while ( -- cnt ) {
        grade.push_back( ven.get() );
    }

}
void Student::print()
{
// string::iterator it;
 for ( int i=0 ; i<id_len; i++)
  cout << id[i];

}
int main()
{
 fstream in;
 in.open ("fee.txt", fstream::in);
 Student x;
 x.read(in);
 x.print();
 return 0;
}

thanks

  • 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-14T14:25:16+00:00Added an answer on May 14, 2026 at 2:25 pm

    You probably should have used cnt-- instead of -- cnt everywhere. The first zero-byte string will trigger an extremely large loop that eventually consumes all memory (except maybe on a 64-bit OS). Actually, don’t even bother with this fix. Loop over get() is extremely inefficient, just call read().

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

Sidebar

Related Questions

I was wondering about the implementation of length of a Java Array. I know
How to obtain the Microphone volume controller in JMF? this is what I have:
I'm trying to create curry function that can be applied to any function and
I'm trying to implement a discrete fourier transform, but it's not working. I'm probably
This question was from Thinking in C++ Vol-1, Chapter 5's exercise No.14: Create a
I have been given the following programming task (edited to obscure mission-specifics): The raw
I want to get a set of some number of letters (default of 7)
I am new to using Fluent NHibernate and NHibernate for the first time. I've
Decompilation so as to fix an old program can be painful. As I'm a
So I making a container class for integers and I want to overload the

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.