string line = "hello there 1234"; istringtream in(line); string s, t, x; int u; in >> s >> t >> u; if (in.fail()) not enough input or 3rd not an int in >> x; if (! in.fail()) error - extra thing on line in.clear() 0: 53 3 1: 17 12 2: 29 15 3: 65 17 4: 12 17 65 29 5: 38 38 6: 99 45 7: 3 53 53 8: 15 29 65 65 9: 45 99 99 A[0] ... A[N-1] b first thing not yet (known to be) in right place s smallest seen so far in inner loop for (boundary = 0; boundary < N - 1; boundary += 1) { smallpos = boundary for (looking = boundary + 1; looking < N; looking += 1) if (A[looking] < A[smallpos]) smallpos = looking; swap(A[smallpos], A[boundary]); }