T
T
Tesla4o2018-05-02 12:46:46
C++ / C#
Tesla4o, 2018-05-02 12:46:46

How to output an array?

Tell me how to display an array, only the part that is initialized? For example, the length of the array is 100,
and the user entered only 5 elements. you need to display only these 5 elements and not the entire array.
for example this code.

int main()
{
#include <iostream>
#include <string>

using namespace std;

int main()
{
  string str[200];
  for (int i = 0; i < 200; ++i)
  {
    getline(cin, str);
    
  }
  
  //Как вывести например только 5 введенных строк???
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Codebaker, 2018-05-02
@Tesla4o

Add a numberOfUserEnteredStrings counter, increment it each time the user enters something.
When displaying the results, loop not up to 200, but already up to numberOfUserEnteredStrings.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question