【发布时间】:2014-02-21 21:44:52
【问题描述】:
我正在尝试读取来自用户的输入,并且我知道我的方法需要一个 char*,但无论如何可以使 cin 的输入能够被该 char 使用? (查看 char* x 处的评论。)
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 风格的字符串