Login or Sign Up
Logging in...
Remember me
Log in
Or
Sign Up
Forgot password or user name?
Log in with
Search in titles only
Search in C only
Search
Advanced Search
Forums
Product Launch
Updates
Today's Posts
Member List
Calendar
Home
Forum
Topic
C
Couldn't understand what my error means
Collapse
X
Collapse
Posts
Latest Activity
Photos
Page
of
2
Filter
Time
All Time
Today
Last Week
Last Month
Show
All
Discussions only
Photos only
Videos only
Links only
Polls only
Events only
Filtered by:
Clear All
new posts
Previous
1
2
template
Next
Savage
Recognized Expert
Top Contributor
Join Date:
Feb 2007
Posts:
1759
#16
Sep 18 '07, 09:40 AM
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
Post
Cancel
blackx
New Member
Join Date:
Sep 2007
Posts:
31
#17
Sep 18 '07, 09:46 AM
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
Post
Cancel
Savage
Recognized Expert
Top Contributor
Join Date:
Feb 2007
Posts:
1759
#18
Sep 18 '07, 10:17 AM
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
Post
Cancel
blackx
New Member
Join Date:
Sep 2007
Posts:
31
#19
Sep 18 '07, 10:28 AM
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
Post
Cancel
Savage
Recognized Expert
Top Contributor
Join Date:
Feb 2007
Posts:
1759
#20
Sep 18 '07, 10:47 AM
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
Post
Cancel
blackx
New Member
Join Date:
Sep 2007
Posts:
31
#21
Sep 18 '07, 10:51 AM
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
Post
Cancel
Savage
Recognized Expert
Top Contributor
Join Date:
Feb 2007
Posts:
1759
#22
Sep 18 '07, 10:56 AM
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
Post
Cancel
Previous
1
2
template
Next
Working...
Yes
No
OK
OK
Cancel
👍
👎
☕
Comment