#include <iostream>

//获取文件的名称,比如D:\\123.json输出123.json,输入123则输出123
void GetFileName(char* path, std::string& name)
{
	char* p = path + strlen(path) - 1;

	while (p != path)
	{
		if (*p == '\\' || *p == '/')
		{
			p++; //向前加一位,去掉斜杠
			name = p;
			return;
		}
		p--;
	}
	name = p;
}


//获取文件的名称,比如D:\\123.json输出123.json,输入123则输出123
void GetFileName2(std::string path, std::string& name)
{
	for (int i = path.size() - 1; i > 0; i--)
	{
		if (path[i] == '\\' || path[i] == '/')
		{
			name = path.substr(i + 1);
			return;
		}
	}
	name = path;
}
//获取文件或者文件夹所在目录,比如D:\123\4.json=>D:\123 D:\123\4=>D:\123,456=>空的
void GetDirName(std::string path, std::string& name)
{
	for (int i = path.size() - 1; i > 0; i--)
	{
		if (path[i] == '\\' || path[i] == '/')
		{
			name = path.substr(0,i);
			return;
		}
	}
	name = "";
}
//获取文件后缀包含点,如果没有找到则返回空,比如123.json=>.json,123=>空的
void GetExtension(std::string path, std::string& suffix)
{
	for (int i = path.size() - 1; i > 0; i--)
	{
		if (path[i] == '.')
		{
			suffix = path.substr(i);
			return;
		}
	}
	suffix = "";
}



int main()
{
	char path[] = "456";
	std::string res;
	GetDirName(path,res);
	std::cout << res << "\n";
	return 0;
}