While loop problems

So I have created program that will take a set of numbers from a file on the command line such as
89 42 168 21 336 11
1 1 2 3 5 8 13 21 34
1 0 3 8 5 6 7 4 9 2
100 200 50 400
and read them in and then sort them using a bubble sort. When I cout the sorted numbers however it only gives me the first line sorted and doesnt cout the other 3 lines. Why is this? Im new to programming so I apologize for any obvious mistakes I may have made. Thank you for all the help! :)
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <sstream>

using namespace std;

// Main Function

int main(int argc, char *argv[]) {

// Declaring strings, bool, ints, and char
string line;
int array[100];
int num, counter, i, j, tmp;
bool swapped;

ifstream file;
ofstream outfile;

file.open(argv[1]);

while(getline(file, line)){
counter = 0;
stringstream ss(line);
while(ss >> num){
array[counter]=num;
counter++;
}

swapped = true;

while (swapped) {
swapped = false;

for (i = 0; i < counter - 1; i++) {


if (array[i] > array[i+1]) {
tmp=array[i];
array[i] = array[i+1];
array[i+1] = tmp;
swapped = true;
}
}
}


for (i = 0; i < counter; i++){
// outfile will replace this
cout << array[i] << " ";
}

cout << endl;

file.close();
}

return 0;
}
You're closing the file at the end of the loop block. It should be after the loop not in it.

BTW, use [code] [/code] tags for code to preserve indentation.
Topic archived. No new replies allowed.