Search
 
SCRIPT & CODE EXAMPLE
 

CPP

how to print an array in cpp in single line

int Grades[5] = { 3, 2, 5, 2 };

cout << "Grades: ";
for (int i = 0; i < sizeof(Grades)/sizeof(int); i++) {
    cout << Grades[i] << ", "; //minus the commas, remove (<< ", ") or to space out the grades, just remove the comma
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ write to file in directory 
Cpp :: Arduino Real TIme Clock 
Cpp :: c++ memset 
Cpp :: How to pass a multidimensional array to a function in C and C++ 
Cpp :: get function in cpp. 
Cpp :: time complexity of best sort algorithm 
Cpp :: string c++ 
Cpp :: qt file explorer 
Cpp :: minimum characters to make string palindrome 
Cpp :: the difference between i++ and ++i 
Cpp :: c++ concatenate strings 
Cpp :: valid parentheses in c++ 
Cpp :: converting int to string c++ 
Cpp :: binary to decimal 
Cpp :: operator overloading c++ 
Cpp :: c++ constructor 
Cpp :: c++ bit shift wrap 
Cpp :: cpp algorithm iota 
Cpp :: largest subarray with zero sum 
Cpp :: C# adding numbers 
Cpp :: uint16_t in c++ 
Cpp :: 3. The method indexOf, part of the List interface, returns the index of the first occurrence of an object in a List. What does the following code fragment do? 
Cpp :: prompt user for bool statement C++ 
Cpp :: sfml thread multi argument function 
Cpp :: C++ Display a text 5 times 
Cpp :: txt to pdf CPP 
Cpp :: what do I return in int main() function c++ 
Cpp :: c++ click event 
Cpp :: transform c++ 
Cpp :: atomic int c++ add 1 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =