这里打印的值是library.h 的片段顺便说一句library.h的这个片断这是为什么不从txt文件
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#pragma warning (disable:4267)
#pragma warning (disable:4311)
#pragma warning (disable:4313)
#pragma warning (disable:4244)
#pragma warning (disable:4996)
#pragma warning (disable:4800)
#pragma warning (disable:4018)
#pragma comment(lib, "library.lib")
using namespace std;
Library.h是一个标题文件,它是一个图形库也包含已包含的大多数C++库,我需要打印来自database1.txt的所有值,btw对不起,如果我的代码看起来像是一场灾难,并未将C++编码四年。
#include <library.h>
#include <iterator>
#include <vector>
#include <sstream>
struct st {
double month;
double day;
double year;
double social;
string fname;
string lname;
double address;
}roll [14];
void rawr (st dat);
void main()
{
ifstream meow("database1.txt");
{
if (meow.fail())
cout << "Not enough data in the file!, NOOB";
}
int n;
while (meow){
double d;
string e, f;
double g;
double a, x, c;
meow>>a;
meow>>x;
meow>>c;
meow>> d;
meow>> e;
meow>> f;
meow>>g;
cout << a<<" "<<x<<" "<< c<< " "<<d<<" "<<e<<" "<<f<<" "<<g;
for (n=0; n<14; n++)
{
stringstream(a)>> roll[n].month;
stringstream(x)>> roll[n].day;
stringstream(c)>> roll[n].year;
stringstream(d)>> roll[n].social;
stringstream(e)>> roll[n].fname;
stringstream(f)>> roll[n].lname;
stringstream(g)>> roll[n].address;
}
for (n=0; n<14; n++)
rawr (roll[n]);
}
}
void rawr (st dat)
{
cout << dat.month<<" "<<dat.day<<" "<< dat.year<< " "<<dat.social<<" "<<dat.fname<<" "<<dat.lname<<" "<<dat.address;
}
解决此类问题的正确工具是您的调试器。在*堆栈溢出问题之前,您应该逐行执行您的代码。如需更多帮助,请阅读[如何调试小程序(由Eric Lippert撰写)](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)。至少,您应该\编辑您的问题,以包含一个[最小,完整和可验证](http://stackoverflow.com/help/mcve)示例,该示例再现了您的问题,以及您在调试器。 –
由于'main'的定义不正确,您可能*问题。 'main'函数返回一个'int'。总是。 –
如果这是纯粹的运气编译它,因为'std :: ifstream'需要''这不在你的包含列表中。 'std :: string'也不会被''完成,或者任何通过'' –
WhozCraig