【发布时间】:2020-10-09 04:00:52
【问题描述】:
我正在尝试从文本文件中获取名称和 3 个数字,然后获取该输入并将名称存储到颜色中,并将 3 个数字存储到 r、g、b 中,然后它将获取 r、g、b 数字和将它们转换为十六进制颜色代码。文本文件格式如下
color1 190 190 190
color2 20 50 70
以下代码是我的问题所在
ifstream ReadFile;
ReadFile.open(filename);
if(ReadFile.fail())
{
cout<<"Could not open "<<filename<<endl;
}
else
{
while ( getline (ReadFile,line) )
{
cout << line << '\n';
}
}
//for(string line; getline(ReadFile, line, '.'); )
//{
//cout<<line<<endl;
//}
ReadFile.close();
//cout<<"Enter the value of RGB(from range 0 to 255):";
cin>>r>>g>>b;
cout<<rgbtohex(r,b,g,true)<<endl;
【问题讨论】:
-
欢迎来到 Stackoverflow!你需要做字符串操作
-
到底是什么问题?您是否收到编译错误或意外结果?