Code:
// ConsoleApplication3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "string"
#include "iostream"
#include "array"
using namespace std;
void nhapmang(string ar[], int n)
{
for (int i = 0; i < n; i++)
{
cout << "Nhap [" << i<<"] :";
cin.ignore();
getline(cin, ar[i]);
}
}
void xuatmang(string ar[], int n)
{
for (int i = 0; i < n; i++)
{
cout << ar[i] << endl;
}
}
int main()
{
int n;
cin >> n;
string *ar = new string[n];
nhapmang(ar, n);
xuatmang(ar, n);
system("pause");
return 0;
}
mneus mình dùng getline như trên thì khi nhập bị mất 1 kí tự đầu.còn cin.getline thì không được mà nó báo lỗi như ảnh.mn giúp vs ạ
