i've managed write random data between 1 , 10 file using sample code:
for (int = 1; <= size; i++) { type = rand () % 3; switch (type) { case 0: afile << rand () % 10; break; case 1: afile << rand () % 10; afile << "\t\t"; afile << rand () % 10; break; case 2: afile << rand () % 10; afile << "\t\t"; afile << rand () % 10; afile << "\t\t"; afile << rand () % 10; } afile << "\t\t" << "// possible type " << << endl; } my output this:
8 // possible type 1 1 7 // possible type 2 4 0 3 // possible type 3 how can format comment make stay in vertical line this:
8 // possible type 1 1 7 // possible type 2 4 0 3 // possible type 3 i've tried setw no success since i'm running loop makes setw inapplicable here. there function me solve problem?
one option update case statement follows:
switch (type) { case 0: afile << rand () % 10; afile << "\t\t\t\t\t\t"; break; case 1: afile << rand () % 10; afile << "\t\t"; afile << rand () % 10; afile << "\t\t\t\t"; break; case 2: afile << rand () % 10; afile << "\t\t"; afile << rand () % 10; afile << "\t\t"; afile << rand () % 10; afile << "\t\t"; }
Comments
Post a Comment