如何使用c++从文本文件中读取特定的值

how to read specific values from text file using c++?

本文关键字:读取 文件 何使用 c++ 文本      更新时间:2023-10-16

我有一个如下的文本文件:

Value1 = windows
Value2 = Processor
Value3 = pwower plug

现在我正在检索完整的文件,如下所示:

std::ifstream myfile;
myfile.open( "D:\values_user.txt", std::ios::in );
if( !(myfile.is_open()) )
{   std::cout << "Error Opening File";
std::exit(0);   }
std::string firstline;

while( myfile.good() )
{
    std::getline( myfile, firstline);
    std::cout<< "n" << firstline <<"n";
}

我想检索窗口,处理器和电源插头,即只是想在'='之后有值。所以,建议我如何才能做到这一点。

根据分隔符(在您的例子中是=)对字符串(firstline)进行标记。

示例如下:

strtok