在常规HTML中,您可以将多个字段POST到数组:
<input type="text" name="arr[]">
<input type="text" name="arr[]">
<input type="text" name="arr[]">
<input type="text" name="arr[]">
Run Code Online (Sandbox Code Playgroud)
如何从WTForms获得此功能?基本上,我有一个用户的表单,然后单击小加号和减号按钮来添加或删除表单中的字段.
我在函数中delete的指针,然后我设置为.但是,在运行该函数后,不再设置,所以我必须再次设置它.aStudentdestroyStudent()aStudentnullptraStudentnullptrnullptr
#include <cstring>
using namespace std;
struct Student {
char * name;
float gpa;
};
Student * createStudent(const char name[], float gpa) {
struct Student * student = new Student;
student->name = (char*)malloc(strlen(name + 1)); //allocate only enough memory to fit the given name
strcpy(student->name, name);
student->gpa = gpa;
return student;
}
bool destroyStudent(Student * aStudent) {
if(aStudent) { //check whether this pointer is already null.
free(aStudent->name);
delete aStudent; // ******This …Run Code Online (Sandbox Code Playgroud) #include <cstring>
using namespace std;
struct Product {
char * name;
float price;
};
int main() {
Product * bread = new Product;
bread->name = new char[6];
bread->name = "bread";
delete[] bread->name; //!!!THE ERROR OCCURS ON THIS LINE!!!
delete bread;
}
Run Code Online (Sandbox Code Playgroud)
给我以下错误:
*** Error in `./out': munmap_chunk(): invalid pointer: 0x0000000000400824 ***
Run Code Online (Sandbox Code Playgroud)
我的问题是,是否有必要删除面包 - >名称,或者删除面包将为我处理.如果有必要删除bread-> name,为什么程序在我尝试时会崩溃?