Set up work path (c + +) __c++

Source: Internet
Author: User

Why do you want to set up a work path? Many of the lab's EXE are dependent on some Lib library ah or XML, any EXE to their own folder for the default work path, if you write an EXE call 1510 Lab EXE, happened to you made the EXE and not 1510 Lab EXE in a folder, Then there will be the 1510 lab EXE that was tuned out of the situation where the XML table was not found, because of the 1510 lab EXE in the default work path to find, the results must not be found, at this time, you need to set the work path, the work path to the 1510 lab exe work path, This will work properly.

The main code is as follows SetCurrentDirectory (A.C_STR ()); Set the work path, which is the path shown by B, where a is a string variable, the path is stored, and the header file Windows.h is required.

Here to pay attention to the point is that C + + path and our daily use of the path is not the same, to be replaced by \, because \ in C + + is a special meaning, can not be used, this may be based on the full code of the following detailed look.


#include "stdafx.h"
#include <iostream>
#include <windows.h>//Note that the two header files are included.
#include <shellapi.h>//Note contains these two header files ...
#include <string>
using namespace std;
int main ()
{
string a = "d:\\ my document \ desktop \\607 b \\library";//input path, note double "\"
string b = "Object beam detect"; b First Input parameters
//a.append ("//...). //set to the current working path is the upper-level
setcurrentdirectory (A.C_STR ()) at that time;  Set the work path, which is the path
ShellExecute (null, "open", "BView.exe", b.c_str (), NULL, sw_show), and/or open B-Display
system ("Pause ")//test with return
0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.