简体   繁体   中英

How can I print values in a loop?

In my code, all values are not printed in sequence.

Only the first value will be printed.

But I want to print the values in the order of the variable in .

in is a variable that takes the number of products.

   for(j=0;j<in;j++){
         cout<<"Id: "<<p1[j].id<<"\t Name: "<<p1[j].name<<endl;
   }

You can use ostream::write . This accepts a character array and the size of the array . The array is copied directly to the streambuffer.

Example:

char array[8];
//fill in array

//Because std::cout is an ostream
std::cout.write( array, 8 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM