How to format output of a SQL query in C++?

Viewed 42

Im working on a school assignment in which i need to format a query of some dummy data. The specific query gathers data on a few fields in a set of two tables, and prints it out to the console in C++.

While this works as expected, the only issue is formatting output so that it appears correctly. In our example output in the assignment document, this is shown as being the proper output

<ID>       <name>           <email>           <phone>         <ext>          <manager>

not the exact spacing but more or less what needs to be done. The initial output i get in the console is similar to this, and looks like:

1056   Tim Tomphson    ttomph@fakeEmailService.com   +1 800 555 1580    x5122   Tom Timsphon 

Until about a few entries down when suddenly the data becomes completely unformatted. enter image description here

Now im confused, cause I thought i had the formatting right, and dont know why its fallen to hell around that point specifically since everything else up to that was basically perfect. and i dont know how to format it right so that it can return to a proper tabular output.

the code im using for this output is

cout << left << setw(10) << temp.empNum << "\t" << temp.firstName << " " << temp.lastName << "\t\t" << temp.email << "\t\t" << temp.phone << "\t\t" << temp.extension << "\t\t" << temp.reportsTo << endl;

I've also tried using printf statements, but that had less luck and was nowhere as close to successful as this command itself...does anyone have any ideas that could help me out?

0 Answers
Related