2009-07-29 73 views
1

讓我們有一個路徑如何用引號括起存儲在變量中的路徑?

C:\Program Files\TestFolder 

這條道路我得到了編程並存儲在varible dirpath(例如)
我現在已經串連字符串

dirpath=getInstallationpath()+"\\ test.dll /codebase /tlb"; 

然後dirpath是成爲

C:\Program Files\TestFolder\test.dll /codebase /tlb 

但我的問題是我已經把路徑用雙引號括起來

"C:\Program Files\TestFolder\test.dll" 

因爲當我直接傳遞dirpath作爲命令行用於regasm在的CreateProcess(),那麼它應該能夠接受C:\程序只是因爲白spaces.so我嘗試很多特技等

dirpath="\ "+getInstallationPath()+" \test.dll /codebase /tlb " 

這樣的,但沒有工作......

所以請HEP我在這方面...提前

謝謝...

+0

這與從http://stackoverflow.com/questions/1177323/how-to-pass-the-directory-path-as-command-line-for-the-process中的問題有何不同? – sharptooth 2009-07-30 04:52:36

回答

2

我可以看到該行的兩個問題。首先,您需要轉義前面的test.dll的反斜槓。其次,用雙引號將路徑包裝起來,要求你也使用引號。

這些變化之後,它應該是這樣的:

dirpath="\""+getInstallationPath()+"\\test.dll\" /codebase /tlb " 

編輯:

固定每馬丁的請求分配。忘記第一個字符串的收盤引號!

+0

它使用dirpath作爲字符串在g ++下編譯。 – Eric 2009-07-29 17:05:31

2

我相信你忘了第二個\「test.dll後

2

對於構建複雜的字符串,使用字符串流通常更容易(也更有效)。

// Note the character(") and the character(\) 
// will need to be escaped when used inside a string 
std::stringstream stuff; 
suff << "\"" 
    << getInstallationPath() << "\\test.dll" 
    << "\"" 
    << "/codebase /tlb"; 
               // 
dirpath = stuff.str(); 
+0

非常感謝你....... – Cute 2009-07-30 11:19:18

相關問題