Couldn't understand what my error means

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Savage
    Recognized Expert Top Contributor
    • Feb 2007
    • 1759

    #16
    Originally posted by blackx
    I just wrote

    txtFile.is_open ()

    in my main...how do I make it return true or false?

    I initialized my values to 0, not 1, so I don't think its because of that.

    Just put it into if statement:

    if(txtFile.is_o pen())

    And if it isn't that try changing in your text file first value(1.0) to something else,and see if your program than prints that.

    Savage

    Comment

    • blackx
      New Member
      • Sep 2007
      • 31

      #17
      I changed the first number in the txt file to 2, and yes, now I get all 2s when I run the code. Any ideas what I did wrong?

      Comment

      • Savage
        Recognized Expert Top Contributor
        • Feb 2007
        • 1759

        #18
        Originally posted by blackx
        I changed the first number in the txt file to 2, and yes, now I get all 2s when I run the code. Any ideas what I did wrong?

        Wait a secound,why is x a integer when you are reading in floats?

        [CODE="cpp"]void Vector::setVect or (string txtFileName) {
        int x;

        ifstream txtFile(txtFile Name.c_str());

        for (int i = 0; i < this->length; i++) {
        txtFile >> x;
        this->contents[i] = x;
        }

        int numberWidth = 8;
        int decimalPlaces = 4;
        for (int i = 0; i < this->length; i++) {
        cout.width(numb erWidth);
        cout << fixed << setprecision(de cimalPlaces) << this->contents[i];
        cout << '\t';
        }

        cout << endl;.
        }[/CODE]

        Comment

        • blackx
          New Member
          • Sep 2007
          • 31

          #19
          whoa! you're right!

          I just changed x to double and I got what I wanted!

          I just spent the last 3 hours trying to fix my code, and all I did wrong was I made x int instead of double! that's crazy.

          Thanks for your help man, I really appreciate it.

          Comment

          • Savage
            Recognized Expert Top Contributor
            • Feb 2007
            • 1759

            #20
            Originally posted by blackx
            whoa! you're right!

            I just changed x to double and I got what I wanted!

            I just spent the last 3 hours trying to fix my code, and all I did wrong was I made x int instead of double! that's crazy.

            Thanks for your help man, I really appreciate it.
            I'm more than happy to help you.

            I think that when x was int stream became corrupted and started to continuously throw in same value.

            Savage

            Comment

            • blackx
              New Member
              • Sep 2007
              • 31

              #21
              Originally posted by Savage
              I'm more than happy to help you.

              I think that when x was int stream became corrupted and started to continuously throw in same value.

              Savage
              that makes sense. Thanks again.

              Comment

              • Savage
                Recognized Expert Top Contributor
                • Feb 2007
                • 1759

                #22
                Originally posted by blackx
                that makes sense. Thanks again.
                Well,that's it then.

                If you face another problem with these two classes,feel free to post again.

                Savage

                Comment

                Working...