2009-07-29 90 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