// Test.cpp : Defines the entry point for the console application.
//vc6.0 编译通过
//2023-10-04
#include <iostream>
#include <string>
#include <shlobj.h>
#define STRICT_TYPED_ITEMIDS
using namespace std;
string getFileName()
{
OPENFILENAME ofn;
char file_name[100];
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = NULL;
ofn.lpstrFile = file_name;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = 100;
ofn.lpstrFilter = TEXT("All\0*.*\0Excel\0*.xls\0") ;
ofn.nFilterIndex = 1;
GetOpenFileName(&ofn);
return (const char*)ofn.lpstrFile ;
}
int main()
{
cout << getFileName() << endl;
return 0;
}
/
#include <stdio.h>
#include <string.h>
//结构声明
struct Item
{
char name[24];
float val;
};
void Writefile(Item & a)
{
strcat (a.name,"\0");
char ch;
FILE *fp;//定义文件流指针,用于打开文件
fp = fopen("0063120.txt","a");//写打开文件
fprintf(fp ,"%s\t%0.2f\n", a.name, a.val);
fclose(fp);//关闭文件a,有打开就要有关闭
}
void Readfile()
{
struct Item b;
FILE *fp;//定义文件流指针,用于打开文件
fp = fopen("0063120.txt","r");//写打开文件
while(!feof(fp))
{
fscanf(fp, "%s\t%f", b.name, &b.val);
if(strlen(b.name) == 0) break;
printf("%s\t%0.2f\n", b.name, b.val);
memset(b.name, 0,sizeof(b.name)) ;
}
fclose(fp);
}
int main()
{
//struct Item a={ "中梃", 2400}; //结构定义并赋值
//Writefile(a);
Readfile();
getchar();
return 0;
}