How to insert a "," in an array?
-
Hi does anyone know how to insert commas in array? example: 2,3 3,3 4,2 I need to show these commas when I execute the program. Pls advice.
-
Hi does anyone know how to insert commas in array? example: 2,3 3,3 4,2 I need to show these commas when I execute the program. Pls advice.
for (int i = 0; i < arraySize-1; ++i) { cout << array[i] << ", "; } cout << array[arraySize-1]; Christian Graus - Microsoft MVP - C++
-
for (int i = 0; i < arraySize-1; ++i) { cout << array[i] << ", "; } cout << array[arraySize-1]; Christian Graus - Microsoft MVP - C++
Christian Graus wrote: for (int i = 0; i < arraySize-1; ++i) { cout << array[i] << ", "; } cout << array[arraySize-1]; Right, but don't forget to test for the empty array condition. The
for
loop checks it itself, but the last sentence may attempt to accessarray[-1]
. -- jlr http://jlamas.blogspot.com/[^]