#include<iostream>
#include<windows.h>
#include<string.h>
using namespace std;
main()
{
string kelime="dir";
system(kelime);
}
,如果我這樣做:char kelime[10]="dir";
C++系統函數不接受字符串?
這是工作,但我想用繩子做呢?有什麼問題,我該怎麼做?
#include<iostream>
#include<windows.h>
#include<string.h>
using namespace std;
main()
{
string kelime="dir";
system(kelime);
}
,如果我這樣做:char kelime[10]="dir";
C++系統函數不接受字符串?
這是工作,但我想用繩子做呢?有什麼問題,我該怎麼做?
system(kelime.c_str());
system()
(和許多其他API)被設計成由C調用,並採取所謂的C-串,它們是單字節的ASCII字符NULL結尾的陣列。
使用std::string::c_str()
從C++ std::string
獲取C字符串。
我不知道。謝謝你解釋。 –
使用kelime.c_str()
訪問舊char
風格
嘗試'系統(kelime.c_str());' – songyuanyao
你的編譯器必須爲古代'string.h'有'的std :: string'。 – StoryTeller
請不要提及你正在得到的確切錯誤 –