我目前正在寫我的課是應該作爲一個很基本的殼轉讓。我差不多完成了,但是我遇到了execvp
和我的字符數組參數問題。這是我的代碼的一小段代碼。C++爲const char *爲const char * const的
//Split the left content args
istringstream iss(left);
while(getline(iss, s, ' ')){
v.push_back(s);
}
//Get the split string and put it into array
const char* cmd_left[v.size()+1];
for(unsigned int i = 0; i < v.size(); i++){
cmd_left[i] = v.at(i).c_str();
}
cmd_left[v.size()] = 0;
v.clear();
,這是由...
execvp(cmd_left[0], cmd_left);
利用我的錯誤是
assign3.cxx:96:34: error: invalid conversion from ‘const char**’ to ‘char* const*’ [-fpermissive]
我明白,問題是,我的字符數組沒有滿常量數據,所以我需要從const char*
到const char* const
。我讀了一些關於const_cast
的內容,但我不確定這是否是我需要做的。
如果你會這麼好心,你能不能幫我把我的字符數組的數組通過該功能可以正確地接受?如果您需要我發佈更多我的代碼,請告訴我。
感謝
啊,非常感謝你。這樣做更有意義。另外,我的代碼的其餘部分只是將字符串拆分爲更易於管理的形式。也許有更好的辦法,但它完成了任務,所以我很滿足。 – Zerocaliber
@ user2272616歡迎您。 – yngccc