strcpy(strucLvkaState->province_code,rs->getString(1).c_str()); /* 省别代码 */ string Province_name=rs->getString(2);
时间: 2024-01-24 11:20:31 浏览: 31
这段代码是在使用C++语言中的MySQL Connector/C++库来操作MySQL数据库。具体来说,它执行了一个查询操作,将结果集中的第一列作为一个字符串类型的省别代码赋值给一个名为strucLvkaState的结构体变量的province_code成员变量。同时,它还将结果集中的第二列作为一个字符串类型的省份名称赋值给了一个名为Province_name的字符串变量。需要注意的是,getString()函数返回的是一个C++标准库中的string类型对象,而c_str()函数则可以将这个string类型对象转换为C风格的字符串类型(即以'\0'结尾的字符数组)。
相关问题
void InitLine() //初始化航线信息 { airline *p,*q; L=(airline *)malloc(sizeof(airline)); L->booked=NULL; L->wait=NULL; L->next=NULL; strcpy(L->end_addr,"00000000"); strcpy(L->line_num,"000"); strcpy(L->plant_num,"0000000"); L->day=L->left=L->total=0; q=L; p=(airline *)malloc(sizeof(airline)); p->booked=NULL; p->wait=NULL; strcpy(p->end_addr,"天津"); strcpy(p->line_num,"004"); strcpy(p->plant_num," 3667894"); p->day=4; p->left=120; p->total=120; p->next=q->next; q->next=p; p=(airline *)malloc(sizeof(airline)); p->booked=NULL; p->wait=NULL; strcpy(p->end_addr,"广州"); strcpy(p->line_num,"003"); strcpy(p->plant_num,"4558934"); p->day=3; p->left=120; p->total=120; p->next=q->next; q->next=p; p=(airline *)malloc(sizeof(airline)); p->booked=NULL; p->wait=NULL; strcpy(p->end_addr,"上海"); strcpy(p->line_num,"002"); strcpy(p->plant_num,"2682154"); p->day=2; p->left=120; p->total=120; p->next=q->next; q->next=p; p=(airline *)malloc(sizeof(airline)); p->booked=NULL; p->wait=NULL; strcpy(p->end_addr,"北京"); strcpy(p->line_num,"001"); strcpy(p->plant_num," 2586934"); p->day=1; p->left=120; p->total=120; p->next=q->next; q->next=p; }
这是一个C语言的函数,用于初始化航线信息。该函数首先创建一个空的头结点L,并将其初始化。然后创建多个航线信息,每个航线信息都会被创建为一个新的节点p,并且将其插入到链表中,使得链表中的节点按照航班的日期从小到大排序。每个节点中都包含了航班的目的地、航班号、飞机号、出发日期、余票数量和总票数等信息。该函数的作用是为航班订票系统提供初始的航班信息。
//读取文件列表函数 int readFileList(const char *basePath, std::vector<std::string> &vfilename, std::vector<std::string> &vfile) { DIR *dir; struct dirent *ptr; char base[1000]; if ((dir = opendir(basePath)) == NULL) { perror("Open dir error..."); exit(1); } while ((ptr = readdir(dir)) != NULL) { if (strcmp(ptr->d_name, ".") == 0 || strcmp(ptr->d_name, "..") == 0) /// current dir OR parrent dir continue; else if (ptr->d_type == 8) /// file { char ch[256]; snprintf(ch, 256, "%s/%s", basePath, ptr->d_name); vfilename.push_back(ptr->d_name); std::string d_name(ch); vfile.push_back(d_name); printf("%s\n", d_name.c_str()); } // else if (ptr->d_type == 10) ///link file // printf("d_name:%s/%s\n", basePath, ptr->d_name); // else if (ptr->d_type == 4) ///dir // { // memset(base, '\0', sizeof(base)); // strcpy(base, basePath); // strcat(base, "/"); // strcat(base, ptr->d_name); // readFileList(base); // } } closedir(dir); return 1; } 优化下上面代码
&fileList)
{
DIR *dir;
struct dirent *ptr;
char base[1000];
if ((dir = opendir(basePath)) == NULL)
{
perror("Open dir error...");
exit(1);
}
while ((ptr = readdir(dir)) != NULL)
{
if (strcmp(ptr->d_name, ".") == 0 || strcmp(ptr->d_name, "..") == 0)
continue;
else if (ptr->d_type == DT_DIR)
{
memset(base, '\0', sizeof(base));
snprintf(base, sizeof(base), "%s/%s", basePath, ptr->d_name);
readFileList(base, fileList);
}
else
{
fileList.push_back(ptr->d_name);
}
}
closedir(dir);
return 0;
}
// 该函数实现了递归遍历指定目录下的所有文件,并将文件名存入到std::vector<std::string>类型的fileList变量中。其中,basePath为要遍历的目录路径,fileList为存放文件名的vector容器。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)