[SOLVED] For Loop Acting Goofy
Trying to make a simple app to output a range of characters to a text file. This is the code:
Code:
#include <iostream>
#include <fstream>
int test[221];
int main ()
{
std::ofstream ascii_file ( "ascii.txt" );
if ( !ascii_file.is_open() )
{
std::cout<<"File could not be opened.\n";
std::cout<<"Press enter key to exit...";
std::cin.get();
return 0;
}
ascii_file<<"ASCII Characters\n";
ascii_file<<"----------------\n";
for ( int i = 179; i <= 220; i = i + 6 )
{
test[i] = i;
/*
std::cout<<test[i]<<": "<<(char)test[i]<<" ";
std::cout<<test[i]++<<": "<<(char)test[i]<<" ";
std::cout<<test[i]++<<": "<<(char)test[i]<<" ";
std::cout<<test[i]++<<": "<<(char)test[i]<<" ";
std::cout<<test[i]++<<": "<<(char)test[i]<<" ";
std::cout<<test[i]++<<": "<<(char)test[i]<<"\n";
*/
ascii_file<<test[i]<<": "<<(char)test[i]<<" ";
ascii_file<<test[i]++<<": "<<(char)test[i]<<" ";
ascii_file<<test[i]++<<": "<<(char)test[i]<<" ";
ascii_file<<test[i]++<<": "<<(char)test[i]<<" ";
ascii_file<<test[i]++<<": "<<(char)test[i]<<" ";
ascii_file<<test[i]++<<": "<<(char)test[i]<<"\n";
}
ascii_file.close();
std::cout<<"File written successfully.\n";
std::cout<<"Press enter key to exit...";
std::cin.get();
return 0;
}
And this is the unexpected output:
Code:
ASCII Borders
-------------
179: ³ 179: ´ 180: µ 181: ¶ 182: · 183: ¸
185: ¹ 185: º 186: » 187: ¼ 188: ½ 189: ¾
191: ¿ 191: À 192: Á 193: Â 194: Ã 195: Ä
197: Å 197: Æ 198: Ç 199: È 200: É 201: Ê
203: Ë 203: Ì 204: Í 205: Î 206: Ï 207: Ð
209: Ñ 209: Ò 210: Ó 211: Ô 212: Õ 213: Ö
215: × 215: Ø 216: Ù 217: Ú 218: Û 219: Ü
I can't seem to get the numbers to orient themselves correctly. Any help would be appreciated.