Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/144.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
地址簿写入文件 我有一个编译程序和所有的地址簿C++程序,但我无法确定如何将它写入文件中,每次退出时都保存数据。这是我的密码: //AddressBook Program #include <iostream> #include <string.h> #include <cstdlib> #include <stdio.h> using namespace std; class AddressBook{ public : AddressBook() { count = 0; } void AddEntry(); void DisplayAll(); void DisplayEntry(int i); // Displays one entry void SearchEntry(); int MainMenu(); struct Entry_Struct { char firstName[ 15 ] ; char lastName[ 15 ] ; char birthday[ 15 ] ; char phone[ 15 ] ; char email[ 15 ] ; }; Entry_Struct entries[100]; unsigned int count; }; void AddressBook::AddEntry() { cout << "Entry number " << (count + 1) << " : " << endl; cout << "Enter First Name: "; cin >> entries[count].firstName; cout << "Enter Last Name: "; cin >> entries[count].lastName; cout << "Enter Date of Birth: "; cin >> entries[count].birthday; cout << "Enter Phone Number: "; cin >> entries[count].phone; cout << "Enter Email: "; cin >> entries[count].email; ++count; // tally total entry count } void AddressBook::DisplayEntry(int i) { cout << "Entry[" << i + 1 << "] : " << endl; // states # of entry cout << "First name : " << entries[i].firstName << endl; cout << "Last name : " << entries[i].lastName << endl; cout << "Date of birth : " << entries[i].birthday << endl; cout << "Phone number : " << entries[i].phone << endl; cout << "Email: " << entries[i].email << endl; } void AddressBook::DisplayAll() { cout << "Number of entries : " << count << endl; for(int i = 0;i < count;++i) DisplayEntry(i); } void AddressBook::SearchEntry() { char lastname[32]; cout << "Enter last name : "; cin >> lastname; for(int i = 0;i < count;++i) { if(strcmp(lastname, entries[i].lastName) == 0) { cout << "Found "; DisplayEntry(i); cout << endl; } } } // Your class AddressBook my_book; int MainMenu() { int num; bool bQuit = false; // Put all your code into a while loop. while(bQuit == false) { cout << "+-------------------------------------+" << endl; cout << "| Address Book Menu |" << endl; cout << "| |" << endl; cout << "| 1- Add an entry |" << endl; cout << "| 2- Search for an entry by last name |" << endl; cout << "| 3- Display all entries |" << endl; cout << "| 4- Exit |" << endl; cout << "| |" << endl; cout << "+-------------------------------------+" << endl; cout << endl; cout << "Please enter a number for one of the above options: "; cin >> num; cout << endl; if (num == 1) my_book.AddEntry(); else if (num == 2) my_book.SearchEntry(); else if (num == 3) my_book.DisplayAll(); else if (num == 4) bQuit = true; else cout << "Invalid choice. Please try again" << endl; cout << endl; } return 0; } int main (){ MainMenu(); return 0; } //地址簿程序 #包括 #包括 #包括 #包括 使用名称空间std; 类通讯簿{ 公众: 通讯录() { 计数=0; } 无效附加项(); void DisplayAll(); void DisplayEntry(int i);//显示一个条目 无效搜索条目(); int main菜单(); 结构条目 { charfirstname[15]; char lastName[15]; char生日[15]; 字符电话[15]; char电子邮件[15]; }; 条目结构条目[100]; 无符号整数计数; }; void AddressBook::AddEntry() { 无法输入[计数]。电话; cout>条目[计数]。电子邮件; ++count;//总计条目计数 } void AddressBook::DisplayEntry(int i) { cout_C++_File_File Io_Addressbook - Fatal编程技术网 条目[计数]。电子邮件; ++count;//总计条目计数 } void AddressBook::DisplayEntry(int i) { cout,c++,file,file-io,addressbook,C++,File,File Io,Addressbook" /> 条目[计数]。电子邮件; ++count;//总计条目计数 } void AddressBook::DisplayEntry(int i) { cout,c++,file,file-io,addressbook,C++,File,File Io,Addressbook" />

地址簿写入文件 我有一个编译程序和所有的地址簿C++程序,但我无法确定如何将它写入文件中,每次退出时都保存数据。这是我的密码: //AddressBook Program #include <iostream> #include <string.h> #include <cstdlib> #include <stdio.h> using namespace std; class AddressBook{ public : AddressBook() { count = 0; } void AddEntry(); void DisplayAll(); void DisplayEntry(int i); // Displays one entry void SearchEntry(); int MainMenu(); struct Entry_Struct { char firstName[ 15 ] ; char lastName[ 15 ] ; char birthday[ 15 ] ; char phone[ 15 ] ; char email[ 15 ] ; }; Entry_Struct entries[100]; unsigned int count; }; void AddressBook::AddEntry() { cout << "Entry number " << (count + 1) << " : " << endl; cout << "Enter First Name: "; cin >> entries[count].firstName; cout << "Enter Last Name: "; cin >> entries[count].lastName; cout << "Enter Date of Birth: "; cin >> entries[count].birthday; cout << "Enter Phone Number: "; cin >> entries[count].phone; cout << "Enter Email: "; cin >> entries[count].email; ++count; // tally total entry count } void AddressBook::DisplayEntry(int i) { cout << "Entry[" << i + 1 << "] : " << endl; // states # of entry cout << "First name : " << entries[i].firstName << endl; cout << "Last name : " << entries[i].lastName << endl; cout << "Date of birth : " << entries[i].birthday << endl; cout << "Phone number : " << entries[i].phone << endl; cout << "Email: " << entries[i].email << endl; } void AddressBook::DisplayAll() { cout << "Number of entries : " << count << endl; for(int i = 0;i < count;++i) DisplayEntry(i); } void AddressBook::SearchEntry() { char lastname[32]; cout << "Enter last name : "; cin >> lastname; for(int i = 0;i < count;++i) { if(strcmp(lastname, entries[i].lastName) == 0) { cout << "Found "; DisplayEntry(i); cout << endl; } } } // Your class AddressBook my_book; int MainMenu() { int num; bool bQuit = false; // Put all your code into a while loop. while(bQuit == false) { cout << "+-------------------------------------+" << endl; cout << "| Address Book Menu |" << endl; cout << "| |" << endl; cout << "| 1- Add an entry |" << endl; cout << "| 2- Search for an entry by last name |" << endl; cout << "| 3- Display all entries |" << endl; cout << "| 4- Exit |" << endl; cout << "| |" << endl; cout << "+-------------------------------------+" << endl; cout << endl; cout << "Please enter a number for one of the above options: "; cin >> num; cout << endl; if (num == 1) my_book.AddEntry(); else if (num == 2) my_book.SearchEntry(); else if (num == 3) my_book.DisplayAll(); else if (num == 4) bQuit = true; else cout << "Invalid choice. Please try again" << endl; cout << endl; } return 0; } int main (){ MainMenu(); return 0; } //地址簿程序 #包括 #包括 #包括 #包括 使用名称空间std; 类通讯簿{ 公众: 通讯录() { 计数=0; } 无效附加项(); void DisplayAll(); void DisplayEntry(int i);//显示一个条目 无效搜索条目(); int main菜单(); 结构条目 { charfirstname[15]; char lastName[15]; char生日[15]; 字符电话[15]; char电子邮件[15]; }; 条目结构条目[100]; 无符号整数计数; }; void AddressBook::AddEntry() { 无法输入[计数]。电话; cout>条目[计数]。电子邮件; ++count;//总计条目计数 } void AddressBook::DisplayEntry(int i) { cout

地址簿写入文件 我有一个编译程序和所有的地址簿C++程序,但我无法确定如何将它写入文件中,每次退出时都保存数据。这是我的密码: //AddressBook Program #include <iostream> #include <string.h> #include <cstdlib> #include <stdio.h> using namespace std; class AddressBook{ public : AddressBook() { count = 0; } void AddEntry(); void DisplayAll(); void DisplayEntry(int i); // Displays one entry void SearchEntry(); int MainMenu(); struct Entry_Struct { char firstName[ 15 ] ; char lastName[ 15 ] ; char birthday[ 15 ] ; char phone[ 15 ] ; char email[ 15 ] ; }; Entry_Struct entries[100]; unsigned int count; }; void AddressBook::AddEntry() { cout << "Entry number " << (count + 1) << " : " << endl; cout << "Enter First Name: "; cin >> entries[count].firstName; cout << "Enter Last Name: "; cin >> entries[count].lastName; cout << "Enter Date of Birth: "; cin >> entries[count].birthday; cout << "Enter Phone Number: "; cin >> entries[count].phone; cout << "Enter Email: "; cin >> entries[count].email; ++count; // tally total entry count } void AddressBook::DisplayEntry(int i) { cout << "Entry[" << i + 1 << "] : " << endl; // states # of entry cout << "First name : " << entries[i].firstName << endl; cout << "Last name : " << entries[i].lastName << endl; cout << "Date of birth : " << entries[i].birthday << endl; cout << "Phone number : " << entries[i].phone << endl; cout << "Email: " << entries[i].email << endl; } void AddressBook::DisplayAll() { cout << "Number of entries : " << count << endl; for(int i = 0;i < count;++i) DisplayEntry(i); } void AddressBook::SearchEntry() { char lastname[32]; cout << "Enter last name : "; cin >> lastname; for(int i = 0;i < count;++i) { if(strcmp(lastname, entries[i].lastName) == 0) { cout << "Found "; DisplayEntry(i); cout << endl; } } } // Your class AddressBook my_book; int MainMenu() { int num; bool bQuit = false; // Put all your code into a while loop. while(bQuit == false) { cout << "+-------------------------------------+" << endl; cout << "| Address Book Menu |" << endl; cout << "| |" << endl; cout << "| 1- Add an entry |" << endl; cout << "| 2- Search for an entry by last name |" << endl; cout << "| 3- Display all entries |" << endl; cout << "| 4- Exit |" << endl; cout << "| |" << endl; cout << "+-------------------------------------+" << endl; cout << endl; cout << "Please enter a number for one of the above options: "; cin >> num; cout << endl; if (num == 1) my_book.AddEntry(); else if (num == 2) my_book.SearchEntry(); else if (num == 3) my_book.DisplayAll(); else if (num == 4) bQuit = true; else cout << "Invalid choice. Please try again" << endl; cout << endl; } return 0; } int main (){ MainMenu(); return 0; } //地址簿程序 #包括 #包括 #包括 #包括 使用名称空间std; 类通讯簿{ 公众: 通讯录() { 计数=0; } 无效附加项(); void DisplayAll(); void DisplayEntry(int i);//显示一个条目 无效搜索条目(); int main菜单(); 结构条目 { charfirstname[15]; char lastName[15]; char生日[15]; 字符电话[15]; char电子邮件[15]; }; 条目结构条目[100]; 无符号整数计数; }; void AddressBook::AddEntry() { 无法输入[计数]。电话; cout>条目[计数]。电子邮件; ++count;//总计条目计数 } void AddressBook::DisplayEntry(int i) { cout,c++,file,file-io,addressbook,C++,File,File Io,Addressbook,这里是一个打开并写入输出文件的基本示例 // basic file operations #include <iostream> #include <fstream> using namespace std; int main () { ofstream outfile; outfile.open ("addressbook.txt"); outfile << "Daffy,Duck,123 Main Street,Anytown,OH,USA,

这里是一个打开并写入输出文件的基本示例

// basic file operations
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream outfile;
  outfile.open ("addressbook.txt");
  outfile << "Daffy,Duck,123 Main Street,Anytown,OH,USA,123-456-7890\n";
  myfile.close();
  return 0;
}
//基本文件操作
#包括
#包括
使用名称空间std;
int main(){
出流孔的直径;
outfile.open(“addressbook.txt”);

outfile您的类需要有一个插入器。它是使用
操作符完成的。您想读/写地址簿文件吗?然后您应该查找ostream、istream并打开。
// Inside your class:
friend std::istream& operator<<(std::ostream& os, const AddressBook ab)
{
    return os << /* ... */
}
std::ifstream in("yourtxtfile.txt");
in << my_book;