Using vector two-dimensional arrays

Source: Internet
Author: User

Using vector two-dimensional array to write a phone book

The code is as follows:

#include <iostream> #include <fstream> #include <string> #include <vector> #include <cctype >int Main (int argc, char *argv[]) {using namespace std;string file_name = "f:\\code\\c++\\c++ Primer 5th\\c++ Primer 5th \\temp\\temp.txt "; ifstream input (file_name); if (!input) {cerr <<" couldn ' t open: "<< file_name << Endl ;}        String Temp;int count = 0;vector<string> storage;          Storage name vector<string> num;  Store a person's phone number vector<vector<string>> phone_num; Store owner's phone number input >> temp;storage.push_back (temp), while (input >> temp) {if (Isalpha (Temp[0])) { Storage.push_back (temp);p hone_num.push_back (num); Num.clear ();} else {num.push_back (temp);}} Phone_num.push_back (num); for (auto Name:storage) {cout << name << "";} cout << endl;for (auto &row:phone_num) {for (auto &col:row) {cout << col << "";} cout << Endl;} Input.close (); return 0;}


The following are the contents of Temp.txt

Morgan 2015552368 8625550123
Drew 9735550130
Lee 6095550132 20155550175 805550000

Here are the results of the program run

  

Using vector two-dimensional arrays

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.