I'm attempting a logical comparison at an element in a char-array based on index number but my compiler says illegal comparison.
(我正在尝试根据索引号对char数组中的元素进行逻辑比较,但是我的编译器说非法比较。)
Any ideas about what's going on?(有什么想法吗?)
#include <iostream>
#include <cstring>
#include <iomanip>
#include <fstream>
using namespace std;
ofstream MyFile("Assignmentfile.txt");
int userno;
char name[16];
char lastname[16];
char address[51];
char cellno[14];
char landlineno[12];
int sent;
void userinput();
void searchfunc();
void deletecontact();
void displaycontact();
void modifycontact();
void sortcontact();
void findcontact();
int main()
{
MyFile<<"First Name Last Name Address Cell Number Landline Number"<<endl;
userinput();
return 0;
}
void userinput()
{
{
cout<<"Would you like to enter a new contact? (1/0) ";
cin>>sent;
while (sent==1)
{
cout<<"Enter Name: ";
cin>>name;
MyFile<<left<<setw(16)<<name<<"|";
cout<<"Enter Last name: ";
cin>>lastname;
MyFile<<left<<setw(16)<<lastname<<"|";
cout<<"Enter Address: ";
cin>>address;
MyFile<<left<<setw(51)<<address<<"|";
cout<<"Enter Cell Number: ";
cin>>cellno;
if (cellno[0]=="+")
{
cout<<"Enter Cell number again starting with +92"; // The problem appears here //
}
MyFile<<left<<setw(14)<<cellno<<"|";
cout<<"Enter Landline Number: ";
cin>>landlineno;
MyFile<<left<<setw(12)<<landlineno<<endl;
cout<<endl;
cout<<"Would you like to enter a new contact? (1/0) ";
cin>>sent;
}
MyFile.close();
}
}
The program must be able to write and read from a text file.
(该程序必须能够写入和读取文本文件。)
It can create contacts, modify them, delete them, sort them and search through them.(它可以创建联系人,对其进行修改,将其删除,对其进行排序并对其进行搜索。)
The problem is that the cell number must start from"+92"
ie "+923454356568"
. (问题在于,单元号必须从"+92"
开始,即"+923454356568"
。)
if (cellno[0]=="+")
and so on would work. (我认为, if (cellno[0]=="+")
等等可以工作。)
I cannot use strings and only have to rely on character type arrays.
(我不能使用字符串,而只能依靠字符类型数组。)
Using strings would make all of this a piece of cake.(使用字符串会使这一切变得轻松。)
Below is the assignment I wish to complete.
(以下是我要完成的作业。)
ask by Hassan Iftikhar translate from so