system()路径中含有 空格与 冒号及斜杠 ( \\与 “”)问题

来源:互联网 发布:办公无线键盘鼠标 知乎 编辑:程序博客网 时间:2024/05/02 22:21
#define _CRT_SECURE_NO_WARNINGS #include <iostream>using namespace std;#include <windows.h>void main(){char*aa = " """""""" ";//system( )1.在路径中含有空格必须 "\" 路径 \""2,\必须改为\\或/  //system("  \"C:/Users/Administrator/documents/visual studio 2015/Projects/0601/0601/0601.exe\"  ");  //但是直接在 2个双冒号之间 加" ,系统是 不认 的  要加\" cout << "aa:" << aa << endl;char*bb = "    \"    ";cout << "bb:" << bb << endl;char*cc = "    \\    ";cout << "cc:" << cc << endl;char*dd = "    \\\\    ";cout << "dd:" << dd << endl;//  好多斜杠\\\\ getchar();//替换路径的\为\\ 。char path[MAX_PATH];GetCurrentDirectory(MAX_PATH, path);strcat(path, "\\0601.exe");//2个斜杠 第一个表示 冒号string input = path;cout << "path:" << path << endl;int pos = 0;while ((pos = input.find('\\', pos)) >= 0){input.replace(pos, 1, "\\\\"); pos += 2;}string newpath = input;cout << "新路径:" << newpath.c_str() << endl; string str1 = "\"";//加入双冒号斜杠 为了得到双冒号而不是\"string str = str1 + newpath + str1;const char*cmd = str.c_str();cout << "cmd:" << cmd << endl;//   组合字符串 getchar();system(cmd);getchar();  }




原创粉丝点击