C++;从textfile读取到double+;价值 我试图读取.txt文件,并将内容保存到C++中的双份。 txt文件的格式为:x(tab)9(tab)comments(newline) 我在C++中需要的是双x=9;

C++;从textfile读取到double+;价值 我试图读取.txt文件,并将内容保存到C++中的双份。 txt文件的格式为:x(tab)9(tab)comments(newline) 我在C++中需要的是双x=9;,c++,text,double,ifstream,getline,C++,Text,Double,Ifstream,Getline,//Read constants from file. string name; double value; double a,b,c,d,th; //these are all stored in the file ifstream fin("File.txt"); while (fin >>name>>value) { getline(fin,name,value); }; 如何进行?谢谢上次格式化提取后,您没有清除换行符std::getline()在找

//Read constants from file.
string name;
double value;
double a,b,c,d,th; //these are all stored in the file

ifstream fin("File.txt");
while (fin >>name>>value)
{
    getline(fin,name,value);

};

如何进行?谢谢

上次格式化提取后,您没有清除换行符
std::getline()
在找到新行时停止读取,因此您应该使用
std::ws

while (std::getline(fin >> name >> value >> std::ws, name))
//                                          ^^^^^^^
{
    // ...
};

你还没有阐明你所面临的实际问题。你介意解释一下这个问题吗?看起来你并不是为了任何其他目的而使用数据,而是为了转换。这可以通过AWK oneliner实现。+1将流提取和
getline
:-)结合起来是多么邪恶啊