Согласно MSDN, Console::ReadLine:
Reads the next line of characters from the standard input stream.
Вариант С++ (без указателей):
#include <iostream>
#include <string>
int main()
{
std::cout << "Enter string:" << flush;
std::string s;
std::getline(std::cin, s);
std::cout << "the string was: " << s << std::endl;
}
Вариант C (с буферами и указателями) также работает с компиляторами C++, но его не следует использовать:
#include <stdio.h>
#define BUFLEN 256
int main()
{
char buffer[BUFLEN]; /* the string is stored through pointer to this buffer */
printf("Enter string:");
fflush(stdout);
fgets(buffer, BUFLEN, stdin); /* buffer is sent as a pointer to fgets */
printf( "the string was: %s", buffer);
}
Согласно вашему примеру кода, если у вас есть структура
patient
(исправлено после замечания Дэвида Хеффермана):
struct patient {
std::string nam, nom, prenom, adresse;
};
Затем должно работать следующее (добавлено ios::ignore
после того, как дополнительная проблема была решена Дэвидом Хеффернаном логическим мышлением). Пожалуйста, НЕ используйте scanf
в своем коде ВООБЩЕ.
...
std::cin.ignore(256); // clear the input buffer
patient *ptrav = new patient;
std::cout << "No assurance maladie : " << std::flush;
std::getline(std::cin, ptrav->nam);
std::cout << "Nom : " << std::flush;
std::getline(std::cin, ptrav->nom);
std::cout << "Prenom : " << std::flush;
std::getline(std::cin, ptrav->prenom);
std::cout << "Adresse : " << std::flush;
std::getline(std::cin, ptrav->adresse);
...
person
rubber boots
schedule
09.10.2012