正在读取c++中的选项卡交付文件
Reading tab delimeted files in c++
我正在做一个项目,确实需要一些帮助。我已经将变量存储到一个文件中,如下所示,但用制表符将它们分隔开。现在我想把它们读出来,作为单独的变量,所以问题是,如果没有标签,我该如何读取它们?我必须解析字符串吗?
void fileManagement::appendCustomeRFile(const Customer &obj)
{
if(tryFile(CFile))
{
ifstream cfile(CFile);
cfile<<obj.ReturnCustomerId()<<"t"<<obj.ReturnFName()<<"t"<<obj.ReturnLName()<<"t"<<obj.ReturnContactNumber()<<"t"<<obj.RetrunBalance()<<"nr";
cfile.close;
}
}
这就是我目前从文件中读取的内容。
void viewCustomerInfo(string contact_N)//
{
tryFile(CFile);
bool found=false;
string retreivedId,retreivedFname, retreivedLname, retreivedNumber;
double retreivedBalance;
ofstream cfile(CFile);
if(cfile.is_open())
{
while(!cfile.eof())
{
cfile>>retreivedId>>retreivedFname>>retreivedLname>>retreivedNumber>>retreivedBalance;
if (retreivedNumber==contact_N)
{
found=true;
cout<<"_______________________________________CUSTOMER INFO_______________________________________n"<<"Customer ID: "<<retreivedId<<"nFirst Name: "<<retreivedFname<<"nLast Name: "<<retreivedLname<<"n";
cout<<"Contact Number: "<<retreivedNumber<<"nCustomer Balance"<<retreivedBalance<<endl;
cout<<"___________________________________________________________________________________________"<<endl;
break;
}
}
}
}
非常感谢您的帮助。非常感谢。
而不是进行
while(!cfile.eof())
试试这个
while(cfile>>retreivedId>>retreivedFname>>retreivedLname>>retreivedNumber>>retreivedBalance)
相关文章:
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- Win32编译器选项和内存分配
- C/C++预处理器是否可以检测一些编译器选项
- 是否有C++编译器选项允许激进地删除所有函数调用,并将参数传递给具有空体的函数
- 将--whole archive链接器选项与CMake和具有其他库依赖项的库一起使用
- 通过选项卡的文本设置QTabWidget顺序
- 通过ccmake在cmake中缓存依赖选项
- 如何传递多个 std::文件系统选项?
- 基于编译器选项的编译二进制路径
- "perf_event_attr"结构的"read_format"属性的选项到底是什么?
- 如何应用 libcurl 的持久连接选项
- 文件中.dat Dlib 选项
- LLVM | codegen 用于带有命令行选项的程序输入功能
- 编译 Boost 时在 OS X 上的"ld:未知选项:-soname"
- 按钮悬停在 QT 中垂直布局的选项卡小部件中不起作用
- Visual Studio C++ 它只构建选项卡中显示的文件吗?
- 在C++不适用于猜数字游戏的情况下再次播放选项
- Qt5 用户界面编译器:-i 选项不可用
- CMake - 更改共享库链接选项
- 正在读取c++中的选项卡交付文件