what is the wrong with this code"length indicator implementation" ?
Posted
by cj
on Stack Overflow
See other posts from Stack Overflow
or by cj
Published on 2010-04-25T05:55:14Z
Indexed on
2010/04/25
6:03 UTC
Read the original article
Hit count: 219
Hello, 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
© Stack Overflow or respective owner