linux :

gcc exp_search.c -o exp_search

error: string: No such file or directory

atoll: 名词环礁 , 环状珊瑚岛

exp_search.c 

代码如下:

#include <string>
#include <stdio.h>
#include <stdlib.h>


using namespace std;


string fn_strGetSubContentFromFile(FILE *fp,long long loff,long long llen);


int main(int argc,char *argv[]){
    if(argc<4){
        printf("请依次指定[文件名] [偏移量] [长度]作为参数,此文件可以输出某文件的指定位置、指定长度的内容.\n");
        return 1;
    }
    long long loff=atoll(argv[2]);
    long long llen=atoll(argv[3]);
    FILE *fp=fopen(argv[1],"r");
    if(fp==NULL){
        printf("指定的文件名无法打开,请确认路径、是否可读等:%s.\n",argv[1]);
        return 1;
    }
    string res=fn_strGetSubContentFromFile(fp,loff,llen);
    printf("%s",res.c_str());
    if(fclose(fp)!=0){
        printf("关闭文件怎么失败了,不应该有的情况.\n");
        return 1;
    }
    return 0;
}
string fn_strGetSubContentFromFile(FILE *fp,long long loff,long long llen){
    string res;
    int ires=fseek(fp,loff,SEEK_SET);
    if(ires!=0){
        printf("发生了错误,根据指定的文件位置读不到任何内容.\n");
        return "";
    }
    char *buff;
    size_t result;
    buff=(char*)malloc(sizeof(char)*(llen+1));
    if(buff==NULL){
        printf("内存分配失败,这种错误可是很少出现的.\n");
        return "";
    }
    result=fread(buff,1,llen,fp);
    if(result!=llen){
        printf("这种情况也不应该出现,没有读到应有的字节数.");
        return "";
    }
    buff[llen]=0;
    res=buff;
    free(buff);
    return res;
}
原因是:这是个 .cpp 文件,不是  .c  文件。改为:

g++ exp_search.cpp -o exp_search

./exp_search  hello.c  6  8

GitHub 加速计划 / li / linux-dash
13
2
下载
A beautiful web dashboard for Linux
最近提交(Master分支:4 个月前 )
186a802e added ecosystem file for PM2 5 年前
5def40a3 Add host customization support for the NodeJS version 5 年前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐