流的问题
Issues with ofstream
本文关键字:问题 更新时间:2023-10-16
我正在完成这段代码,但我想知道为什么我不能使用 ofstream 输出存档。
我做错了什么?
问题出在第 61 行。编译器说:错误,'struct std::stringstream' 没有名为 aux4 的成员。
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <fstream>
#include <math.h>
#include <iostream>
#include <sstream>
using namespace std;
class validate {
public:
int aa, mm , dd ;
string guy;
public:
validate ( int x, int y, int z){
aa=x; mm=y; dd=z;
}
bool check ( int aa, int mm, int dd){
if ( aa >0){
if( mm == 01 || mm== 03 || mm == 05 || mm == 07 || mm == 08.0 || mm == 10 || mm == 12){
return dd <=31;
}
else if ( mm == 04 || mm == 06 || mm == 09.0 || mm == 11){
return dd <=30;
}
else {
return dd <=28;
}
}
}
};
int main (){
int aa, mm, dd, key;
string name, date, aux1, aux2, aux3;
stringstream aux4;
do {
cout<<"Name:"<<endl;
cin>>name;
cout<<"Enter date of birth:"<<endl;
cin>>date;
aux1= date.substr(6,9);
aa = atoi(aux1.c_str());
aa=2012-aa;
aux2= date.substr(3,4);
aux2=aux2.substr(0,2);
mm = atoi(aux2.c_str());
aux3= date.substr(0,2);
dd = atoi(aux3.c_str());
aux4 << dd << mm << ".txt";
ofstream file(aux4.aux4().c_str(), fstream ::app);
file<<aa<<"years"<<name<<endl;
file.close();
cout<<"Enter key != 0 if you want to continue ( Ideally press 1):"<<endl;
cin>>key;
}while ( key != 0);
cout<<"Thanks! End of line."<<endl;
system ("PAUSE");
return 0;
};
编译器直接指出了问题所在。 你可能的意思是:
aux4.str().c_str()
而不是:
aux4.aux4().c_str()
std::stringstream
没有aux4()
方法。
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 为"adjacent"变量赋值时出现问题
- 我的神经网络不起作用 [XOR 问题]
- 在Ubuntu 16.04上安装Cilk时出现问题
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 编译包含字符串的代码时遇到问题
- Project Euler问题4的错误解决方案
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 一个关于在C++中重载布尔运算符的问题
- 首要问题的答案让值班员搞错了
- setlocale的C++土耳其字符串问题
- 如何重构类层次结构以避免菱形问题
- 基于boost的程序的静态链接——zlib问题
- C++格式化输出问题
- 使用mongocxx驱动程序时包含头文件问题