-1
#include <iostream>
#include <chrono>
#include <thread>
using namespace std;

constexpr auto MAX_NUM_LEN = 10;

int main() {
    string a_num[MAX_NUM_LEN];

    cout << "Type your full ID" << endl;
    cin.getline(a_num, MAX_NUM_LEN, '.');

    cout << "\nyour input is: " << a_num;
}

Link to my embedded image of the program i did in VS code [1]: https://i.stack.imgur.com/TM7BC.jpg

  • Please [edit] your question and include whatever error you're getting as text, not as an image. – Stephen Newell Feb 18 '22 at 04:49
  • 1
    `a_num` is an array of `string`s, but `getline()` expects an array of `char`s (actually a pointer to it). – frippe Feb 18 '22 at 05:09
  • See [std::basic_istream::getline](https://en.cppreference.com/w/cpp/io/basic_istream/getline) compared to [std::getline](https://en.cppreference.com/w/cpp/string/basic_string/getline). The first expects a character array (or allocated block), the second expects a `std::string`. – David C. Rankin Feb 18 '22 at 07:42

1 Answers1

1

Use char a_num[MAX_NUM_LEN]; instead of string a_num[MAX_NUM_LEN];

Your code will run.

when you use cin.getline() function, then its first parameters would be either a constant character pointer or a character array name.

Please check following resources to learn more about getline

Md. Faisal Habib
  • 1,014
  • 1
  • 6
  • 14