-2
我想讀取來自用戶的輸入,我知道我的方法需要一個char *但是有無論如何使cin的輸入能夠被該char使用? (看在字符* X的評論。)將字符串char *字符串讀入文件?
string y;
cout << "Enter your file: ";
cin >> y;
char * x = //here is where the string needs to go. If I type in the actual address it works, but I need it to work when the user just cin's the address//
string line,character_line;
ifstream myfile;
myfile.open (x);
while(getline(myfile,line))
{
if (line[0] != '0' && line[0] != '1')
{
character_line = line;
}
}
使用std :: string :: c_str()來轉換爲一個c樣式的字符串 –