fork download
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <sstream>
  4.  
  5. struct student
  6. {
  7. char* name;
  8. char* subject;
  9. int mark;
  10. };
  11.  
  12. void LineToStudent(student *Student, std::string &line)
  13. {
  14. std::istringstream iss(line);
  15. std::string word;
  16.  
  17. iss >> word;
  18. Student->name = new char[word.length()+1];
  19. strcpy(Student->name, word.c_str());
  20.  
  21. iss >> word;
  22. Student->subject = new char[word.length() + 1];
  23. strcpy(Student->subject, word.c_str());
  24.  
  25. iss >> Student->mark;
  26. }
  27.  
  28. void ClearStudent(student *Student)
  29. {
  30. delete [] Student->name;
  31. delete[] Student->subject;
  32. delete Student;
  33. }
  34.  
  35. int main()
  36. {
  37. std::string line = "Vasya History 2";
  38.  
  39. student *Student = new student;
  40. LineToStudent(Student, line);
  41.  
  42. std::cout << "Name: " << Student->name << "\nSubject: " << Student->subject << "\nMark: " << Student->mark;
  43.  
  44. std::cin.get();
  45. ClearStudent(Student);
  46. return 0;
  47. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'void LineToStudent(student*, std::string&)':
prog.cpp:19:39: error: 'strcpy' was not declared in this scope
     strcpy(Student->name, word.c_str());
                                       ^
stdout
Standard output is empty