vs读取.txt文件内容

冷不防 2022-04-05 14:19 540阅读 0赞

//vs读取.txt文件内容,首先确定.txt文件的位置,

string filename =“//.txt”

//打开文件

ifstream camfile(filename, ios::in);

//判断是否为非空

if (!camfile)

//取.txt中的第一行内容

string s;

string newFilename;
while (getline(camfile, s))

//以上三句将.txt中的第一行字符串赋值给s,依次循环,取出所有的行字符串

//string 转 char[]

strcpy(c, s.c_str());

/从字符串最后取.后面的字符

char *ext = strrchr(c, ‘.’); //c 开始为 E:\\TEST\\tt.dat, 执行后 c 为E:\\TEST\\tt, 则 ext 为dat

//char[] 转string

string = c ; //直接赋值

发表评论

表情:
评论列表 (有 0 条评论,540人围观)

还没有评论,来说两句吧...

相关阅读