⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 establish.h

📁 C++实现简单数据库管理系统
💻 H
字号:
#ifndef _ESTABLISH_H
#define _ESTABLISH_H
#include "common.h"

bool Check_Digit_Fomat(string& str)// how to check whether the data is float or double?
{
	for (size_t i = 0 ; i<str.length();++i)
		if(!isdigit(str[i]))
			return false;
	return true;
}
int establish(string& table_name,const char* data_path)
{
	
	map<string, list<column *> *  >::iterator map_ptr;
	map_ptr = SQL.find(table_name);
	if(map_ptr==SQL.end())
	{
		cerr<<"table don't exist\n";
		return -1;//table not exist
	}
	ifstream in;
	in.open(data_path);
	if (!in.is_open())
	{
		cerr<<"can't open the file\n";
		return -2;//can't open the file
	}
	string strline;
	string str;
	int count = 0;
	while (getline(in,strline))
	{
		int i = 0;
		while(i!=strline.length()-1)//change the , to blank
		{
			if(strline[i]==',')
				strline[i]=' ';
			++i;
		}
		istringstream iss(strline);
		list<column*>::iterator ptr = (*(map_ptr->second)).begin();//table.begin();
		for( ; ptr!=(*(map_ptr->second)).end() ; ++ptr)
		{
			iss>>str;
			if (((*ptr)->type_float&&Check_Digit_Fomat(str))||((*ptr)->type_char))// check the data format
				(*ptr)->data.push_back(str);
		}
		count++;
	}
	in.close();
	return count;
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -