Thank all of you for your help,
I took all of your suggestions into account and made some changes in my code. Ancient Dragon, I took your advice on the string, which I think is more appropriate since I don't know how long the input may be. The thing is, I'm not trying to pushback the string. I use a string so I can work on one line at a time. Then, I had a thought. In the long run, I'm trying to use a mergesort to sort each line and output on its own line. I think what I'm going to try is something like this:
psuedocode:
vector<vector<float>>inputlines
vector<float>floatvector
while (infile) {
extract one line into a string
put the string into a strstream
while (mystrstream) {
mystrstream >> myfloat
floatvector.pushback
}
inputlines.pushback(floatvector)
}
Hopefully my psuedo code is psuedoreadable. I was thinking about creating a vector to hold each line of input, and gathering all the input at the beginning of the program. Then in the next procedure merge sort each input line and then output them.
Ok, so, with that unneccessary information, I did run into another problem even with my modified code. At the end of the run, each vector has one too many numbers still. The last number is always repeated. I also printed out the sizeof each vector, and it comes to 11, instead of the 10 inputs on each line. I'm not sure why the last number is being duplicated every time. Should I try a different kind of loop? Maybe a do-while and check the status of the stream at the end of the loop? My in.dat and my output are at the end of the post.
#include <iostream>
#include <fstream>
#include <strstream>
#include <string>
#include <vector>
using namespace std;
void main() {
ifstream in("in.dat");
vector<float>numbers;
float myfloat;
string input;
while (in) {
getline(in, input);
numbers.clear();
strstream myss;
myss << input;
while(myss) {
myss >> myfloat;
numbers.push_back(myfloat);
}
for (int a = 0; a < numbers.size(); a++) // outputs one line
cout << numbers[a] << ", ";
cout << endl;
cout << "sizeof numbers: " << numbers.size() << endl;
}
}
OUTPUT:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10,
sizeof numbers: 11
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 20,
sizeof numbers: 11
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 30,
sizeof numbers: 11
30,
sizeof numbers: 1
in.dat:
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30