我想串入文本文档中列出的电话号码
I want to string in phone numbers that are listed in a text document
我自己编写了整个程序,该程序应该模拟手机上的来电。 我已经修复了程序上的每一个错误,但我从未能够成功地将数字逐行拉入我所做的队列中。 我的问题是我使用 getline 从文本中绘制线条的正确方法是什么? 这是我的程序。
#include <string>
#include <queue>
#include <deque>
#include <iostream>
#include <fstream>
#include <stack>
using namespace std;
class cell
{
public:
cell();
void upload( string left );//Insert in order.
void printnew();//Print call just recieved.
void printlater();//Print calls for later.
void decidenew();// Prompts user to decide what to do with recent calls.
void decidelater();// Prompts user to decide what to do with call back numbers.
void correctionnew();//Corrects the amount of numbers in new calls list.
void correctionlater();//Correxts the amount of number in the call back list.
private:
queue<string> N;
queue<string> O;
queue<string> T;
stack<string> Tem;
};
int main()
{
string left;
int i=1;
cell num;
num.upload( left );
int n=1;
while(i != 3)
{
cout << "Please check for recent calls." << endl;
num.upload(left);
cout << "This is the main menu and here are your options:" << endl;
cout << "Press 1 to view your recent calls" << endl;
cout << "Press 2 to view your call back list" << endl;
cout << "Press 3 to turn off cellphone" << endl;
cin >> i;
if(i = 1)
{
num.printnew();
num.decidenew();
num.correctionnew();
num.correctionlater();
}
if(i = 2)
{
num.printlater();
num.decidelater();
}
}
system("Pause");
return 0;
}
void cell::printnew()
{
cout << "Here is the list of the latest callers:" << endl;
while(N.empty())
{
cout << N.front();
T.push(N.front());
N.pop();
}
while(T.empty())
{
N.push(T.front());
T.pop();
}
}
void cell::printlater()
{
cout << "Here is the list of your call back list:" << endl;
while(!O.empty())
{
cout << O.front();
T.push(O.front());
O.pop();
}
while(!T.empty())
{
O.push(T.front());
T.pop();
}
}
void cell::decidenew()
{
int p=0;
while(!N.empty() || p != 4)
{
cout << "What would you like to do with" << N.front() << "?" << endl;
cout << "You can:" << endl;
cout << "Press 1 to call back." << endl;
cout << "Press 2 to ignore the call." << endl;
cout << "Press 3 to Send to call back list." << endl;
cout << "Press 4 to return to the main menu." << endl;
cin >> p;
if(p = 1)
{
N.pop();
}
else if(p = 2)
{
N.pop();
}
else if(p = 3)
{
O.push(N.front());
N.pop();
while(!O.empty() || N.front() != O.front())
{
T.push(O.front());
O.pop();
}
if (N.front() != O.front())
{
O.push(N.front());
N.pop();
}
while(!O.empty())
{
T.push(O.front());
O.pop();
}
while(!T.empty())
{
O.push(T.front());
T.front();
}
}
else if(p = 4)
{
}
else
{
cout << "That is an incorrect input, please try again." << endl;
}
}
}
void cell::decidelater()
{
int dummy = 0;
while(!O.empty() || dummy != 4 )
{
cout << "What would you like to do with" << O.front() << "?" << endl;
cout << "You can:" << endl;
cout << "Press 1 to call back." << endl;
cout << "Press 2 to delete number." << endl;
cout << "Press 3 to keep and call later." << endl;
cout << "Press 4 to go back to main menu." << endl;
cin >> dummy;
if( dummy = 1)
{
O.pop();
}
else if( dummy = 2)
{
O.pop();
}
else if( dummy = 3)
{
T.push(O.front());
O.pop();
}
else if( dummy = 4)
{
}
else
{
cout << "That is an incorrect input, please try again." << endl;
}
while(!T.empty())
{
O.push(T.front());
T.pop();
}
}
}
void cell::upload( string left)
{
int g = 0;
string item;
fstream myfile;
myfile.open("CALLS.txt");
while(!myfile.eof || g != 3)
{
getline( myfile, left);
while(!N.empty() || left != N.front())
{
T.push(N.front());
N.pop();
}
if(left != N.front())
{
N.push(left);
}
while(!N.empty())
{
T.push(N.front());
N.pop();
}
while(!T.empty())
{
N.push(T.front());
T.pop();
}
g++;
}
while(!N.empty())
{
Tem.push(N.front());
N.pop();
}
while(!Tem.empty())
{
N.push(Tem.top());
Tem.pop();
}
g=0;
}
void cell::correctionnew()
{
int l = 0;
while(!N.empty())
{
T.push(N.front());
N.pop();
}
while(!T.empty() || l != 8)
{
N.push(T.front());
T.pop();
l++;
}
}
void cell::correctionlater()
{
int m = 0;
while(!O.empty())
{
T.push(O.front());
O.pop();
}
while(!T.empty() || m != 3)
{
O.push(T.front());
T.pop();
m++;
}
}
我认为
这段代码不应该编译。如果它确实编译了,问题显然是不应该编译的内容:
while (!myfile.eof || g != 3)
这一行有两个问题,其中一个阻止它编译(你可能打算写myfile.eof()
;注意额外的括号),另一个是语义(假设添加了缺少的括号): 流无法提前知道尝试读取的内容。因此,始终有必要在尝试读取后检查读取是否成功。这一行可能应该看起来像这样:
while (g != 3 && std::getline(myfile, left))
相关文章:
- 正在查找文档以获得PS4平台的C++中的设备信息
- 如何在文档文件夹中创建目录
- 当Microsoft文档仅包含 C# 示例时,如何查找 C++ 包含文件名
- 通过构造函数创建一些值并尝试添加到文档中使用 rapidjson 不起作用
- 关于类的 Python 文档 - 对C++的引用不正确
- C++/autoconf 等效于文档库要求.txt的要求是什么?
- mbed:使用 USB 文档库编译会导致错误
- C++ VISUAL STUDIO:GLFWwindow没有初始化,即使它是在文档中编写的并且以前工作过
- 使用 yaml-cpp 更新 YAML 文档的节点和值
- C++ 电话号码字母拨号程序 - 语法错别字?还是非 ASCII 字符?
- 在加载 MSHTML 文档之前从 MSHTML 文档中删除无效的 URL
- 如何在C++中表示JSON文档的递归对象结构?
- 如何查找 Redshift Maya API 文档?
- 如何使用值模板编写文档测试用例?
- 如何使用 Gradle DSL(领域特定语言)上的文档?
- ncurses 找不到任何关于cchar_t的文档
- 提取狮身人面像文档中的C++代码片段
- 关于 API 文档和设备操作 在助手-sdk-cpp 上
- 我想串入文本文档中列出的电话号码
- 在生成的 Word 文档中插入并激活电话号码