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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:09:18+00:00 2026-06-13T08:09:18+00:00

This is the definition of my class: class BPP { unsigned n; /* nº

  • 0

This is the definition of my class:

class BPP
{
    unsigned            n;                  /* nº de instancias */
    vector<string>      nombre_instancia;   /* nombre de la instancia*/
    vector<unsigned>    n_objetos;          /* nº de objetos a almacenar en cada instancia */
    vector<unsigned>    C;          /* capacidad máxima de cada contenedor */
    vector<unsigned>    mejor;              /* mejor nº mínimo de contenedores usados (m*) */
    vector< vector<unsigned> > tam_objeto;

That’s my complete constructor:

BPP :: BPP(char fich1[])
{
    ifstream file1; string str; unsigned a, b, c, d;
    file1.open(fich1);
    if (file1.is_open()){ 
        file1 >> (unsigned &) n;
        for (unsigned k = 0 ; k < n ; ++k){
            getline(file1, str); nombre_instancia.push_back(str);
            file1 >> a; n_objetos.push_back(a);
            file1 >> b; C.push_back(b);
            file1 >> c; mejor.push_back(c);
            for (unsigned h = 0 ; h < a ; ++h){
                file1 >> d; tam_objeto[k].push_back(d);
            }
        }
    }
    file1.close();
}

The 5 first lines in fich1 are:

10
 P_0 /*Notice the space in the beginning of the line, and in the end*/
150 120 52
30
34

And the output is all values readed are 0 (if unsigned) or “” (if string)

  • 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-06-13T08:09:20+00:00Added an answer on June 13, 2026 at 8:09 am

    The problem is that the new-line character after the 10 is not consumed by:

    file1 >> (unsigned &) n; // Why the cast here?
    

    this means that the getline(file1, str) call reads the new-line character only, an empty line. The next input operation is:

    file1 >> a;
    

    which fails because P_0 is not a valid unsigned int. This failure prevents any further reads from the file1 stream (its failbit is set).
    To resolve, you could just simply call getline() twice, ignoring the result of the first call.

    Check the result of all reads to detect failure. Doing so would have alerted you to the read failures.

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

Sidebar

Related Questions

Given this definition: class Foo(var x: String) {} object Helper { def model[T](get: ⇒
For this class definition: type Foo(f1: int, f2: string) = member x.F1 = f1
I have a class like this public class Definition { public virtual string Name
In C#, given a class definition like this: public class SomeObject { public String
given this class definition: public class Frame { IFrameStream CapturedFrom; } I want implement
I've embedded a SWF into a class using this syntax above my class definition:
class Test { enum{}; ... }; Is this empty enum definition portable? Compiles in
I have this definition of the function in my class. The .hpp file: class
I'm having problems with this class definition because of the definition of $directories .
I have this definition for my Test class: #ifndef TEST_H #define TEST_H #include <iostream>

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.