用宽字符打开文件进行字符串搜索

#include 
#include 
#include //解决不能输出宽字符中文

int main()
{
	setlocale(LC_ALL, "chs");//配合locale.h解决不能输出宽字符中文问题
	FILE *fp;
	TCHAR temp[256];
	if ((fp = _wfsopen(_T("E:\\SSE1.4.3\\SSEMU.ini"), _T("r"), _SH_DENYWR)) == NULL)
	{
		printf("不能打开文件!!!\n");
		return false;
	}
	while (fgetws(temp, 255, fp))
	{

		temp[wcslen(temp) - 1] = '\0';
		if (wcsstr(temp, _T("发射器")) != NULL)
		{
			wprintf_s(_T("%ls\n"), temp);
			fclose(fp);
			return true;
		}
	}
	fclose(fp);
	return false;
}

 

你可能感兴趣的:(C语言)