C++ cout overwriting itself while in for loop -


the cout statement in loop:

for (vector<student>::iterator qw = students.begin(); qw != students.end(); ++qw){     student = *qw;     name = a.getname();     regno = a.getregno();     std::cout << "name: "<< name << " reg number: " << regno << endl; } 

is creating odd behavior, cout should print this:

name: mike sanderson reg number: 10101

however prints out it:

reg number: 10101on

it seem me after second part of cout statement going start of line , overwriting itself, why? hope guys can me , if need more info let me know!

this carriage return character (that is, \r in string literal). assume name string has \r @ end of it. you'll need figure out how got there , remove it.

i'm guessing perhaps read names file, , file created on windows, ends lines \r\n default. c++ handle conversion between line endings when reading text file, if you're reading file binary file , using \n delimiter, you'll have problem. \r read though part of line.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -