//C语言写文件
void write(){
char ch[]={"abvjdkfljdancdkjfdaknmvkjfads1234568970fjkdlajf;angkjfjdanjkhfiou435jfg0309uhjfghjhfdjabndasjkvgfjgh\n"};
FILE* fp= fopen("text.txt","w");
if(fp)
{
int len=sizeof (ch)-1;
for(int i=0;i<1000000;++i)
{
fwrite(ch,len,1,fp);
}
fclose(fp);
}
}
// FILE* fp = fopen("data.mp4", "ab");
// fwrite(buffer, 1, dateLen, fp);
// fclose(fp);
//C语言写文件
void read()
{
//FILE *fp1 = fopen("/home/ubuntu/work/oos/testDemo/unnamed.jpg", "rb");
char *bufftotal = (char *) malloc(size);//new char[1000*10*1000];
int count = 0, i = 0, totalCount = 0;
if (fp1) {
char buff[1000] = {'\0'};
while ((count = fread(buff, 1, 1000, fp1)) != 0) {
memcpy(bufftotal + i * 1000, buff, count);
++i;
totalCount += count;
}
} else {
return 0;
}
}
//C++读文件
void read(std::string filePath){
std::ifstream in(filePath.c_str());
if(!in) {
return false;
}
std::string line;
std::string jsonConfig;
while(getline(in, line))
{
jsonConfig.append(line);
}
in.close();
}
//C++写文件
void Write(){
std::ofstream out("storageIndex.txt",std::ios::app);
if(out){
for(int i=1000;i<1956;++i){
out<<i<<std::endl;
}
out.close();
}
std::ifstream in("storageIndex.txt");
std::string getData;
while(getline(in,getData)){
int n=std::atoi(getData.c_str());
std::cout<<getData<<std::endl;
}
}
C/C++读写文件
最新推荐文章于 2023-01-10 01:14:16 发布