-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样式的字符串 –