Instead of sizeof(line), use line.size().

Also, don't forget to reset x to 0 after each run of the inner loop. It might be better to use < instead of != because that would have caught this problem.