【发布时间】:2015-03-19 02:53:48
【问题描述】:
我一直在为当地... 地方制作一个程序,该程序将计算应订购多少比萨饼。然而,问题甚至不在于计算,而在于保存登录 ID 的文件。数据。
#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <fstream>
using namespace std;
string logs[20];
void test(ifstream& IN, string logs[], ofstream& OUT);
void introduction();
int logging_in(string id, string logs[]);
void menu();
string newl = "\n";
string dnewl = "\n\n";
string tnewl = "\n\n\n";
string qnewl = "\n\n\n\n";
string pnewl = "\n\n\n\n\n";
int main()
{
ifstream IN;
ofstream OUT;
string id;
IN.open("loginn.dat");
cout << IN.is_open();
test(IN, logs, OUT);
string sup;
int receive = 0;
introduction();
return 0;
}
void test(ifstream& IN, string logs[], ofstream& OUT)
{
for (int x = 0; x < 20; x++)
{
IN >> logs[x];
}
IN.close();
OUT.open("loginn.dat");
for (int x = 0; x < 20; x++)
{
OUT << logs[x] << " " << "hue" << " ";
}
}
void introduction()
{
string cont;
cout << "Hello. I am the..." << dnewl
<< "Statistical" << newl << "Pizza" << newl
<< "Order" << newl << "Amount" << newl
<< "Diagnostic." << dnewl
<< "Otherwise known as Pizzahand. I will be assisting you to estimate the \namount of pizza that is to be ordered for <INSERT NAME>, as to \neliminate excessive ordering."
<< tnewl;
cout << "Press Enter to continue..." << newl;
cin.get();
}
理论上,这应该在执行其余代码之前输出数组“logs[]”。当我除了主要功能之外没有其他功能时就是这种情况。当我开始使用我的下一个函数“introduction()”时,这里读取文本文件的代码
for (int x = 0; x < 20; x++)
{
IN >> logs[x];
}
似乎被打乱了。而不是在其他任何事情之前执行此任务,它似乎是在程序的最后执行它,因为我已经通过在程序仍在读取“test()”时输出其内容进行测试,但没有运气。然而,在主函数返回“0”后,我看到我的程序已正确地将数据输出到测试文件“loginns.dat”中。 我的程序必须在开始时读取此登录 ID 数据,因为当程序转换为登录时,需要该数据。另外,我尝试将这些数组和 for 循环放置在不同的位置:登录函数本身、主函数,甚至是我绝望创建的另一个函数。
我已经搜索了好几个小时来解决这个问题,但无济于事,我又试验了好几个小时。我试图解决这个问题的每一步都会导致更多的死胡同,或者更多的问题。从这个学年是学习 c++ 的第一年的意义上说,我是一个初学者,我迫切需要专家意见(或任何知识渊博的人)来帮助我面对正确的方向。
谢谢。
【问题讨论】:
-
我试图了解您的问题,但没有成功。
标签: c++