急求救:C++

来源:百度知道 编辑:UC知道 时间:2024/06/15 05:32:38
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include <stdlib.h>

void main(){fstream file;
char a[20]="c8k";
char b[20];
char c[]=".cpp";
char E[20]="d:\\";

strcat(E,a);strcat(E,c);
system("notepad E");}

这是我的源程序,运行是我的希望是打开E这个字符串所代表的路径的文件,
可是程序打开的是以字母'E‘为路径的文件,应该怎么办?

E是个变量啊

char pre[] = "notepad ";
strcat(pre, E);
system(E);

OK了

#define E D:\

#include<iostream.h>
#include<fstream.h>
#include<string.h>

#include <stdlib.h>
#include <stdio.h> //sprintf需要包含这个头文件

void main(){fstream file;
char a[20]="c8k";
char b[20];
char c[]=".cpp";
char E[20]="d:\\";
strcat(E,a);
strcat(E,c);
sprintf(b, "notepad %s", E); //使用sprintf
system(b);
}

或者

#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include <stdlib.h>

void main(){fstream file;
char a[20]="c8k";
char b[20];
char c[]=".cpp";
char E[20]="notepad d:\\"; // notepad写在这里

strcat(E,a);
strcat(E,c);
system(E);<