Question

In: Computer Science

Please answer in C++ Thanks! Use an istream_iterator, the copy algorithm and a back_inserter to read...

Please answer in C++ Thanks! Use an istream_iterator, the copy algorithm and a back_inserter to read the contents of a text file that contains int values separated by whitespace. Place the int values into a vector of ints. The first argument to the copy algorithm should be the istream_iterator object that's associated with the text file's ifstream object. The second argument should be the istream_iterator object that's initialized using the class template istream_iterator's default constructor-- the resulting object can be used as an "end" iterator. After reading the file's contents, display the contents of the resulting vector.

Solutions

Expert Solution

Implemetation of above program in C++

Please hit that like button or thumbs-up,it really motivates me.>3

Program.cpp

// Incliding needed standard libraries

// You can use <bits/stdc++.h> to inclue all libraries without one by one.


#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <fstream>

using namespace std;

int main()
{
std::vector< int > showVector; //Making a vector

std::ifstream inputFile("E:/a.txt", std::ios::in); // Reading a.txt from location E:/a.txt


std::istream_iterator<int> inputFromFile(std::cin); // istream_iterator, you can use inputFile on the place of std::cin

   // Copy file content to vector list
std::copy(inputFromFile, std::istream_iterator< int >(),back_inserter(showVector ));

for ( int i=0;i<showVector.size(); i++) // Until size of vector
std::cout << showVector[i] << "\t"; // Printing Result

std::cout << std::endl;

return 0;
}

And Please use a proper C++ IDE to get desired output and also give read permissions.

And do not foeget to hit that like button>3 Thank you!!


Related Solutions

please read and answer this questions please and thanks. CERTIORARI TO THE UNITED STATES COURT OF...
please read and answer this questions please and thanks. CERTIORARI TO THE UNITED STATES COURT OF APPEALS FOR THE SECOND CIRCUIT Syllabus Held: The Court of Appeals erred in concluding that, when the Department of Housing and Urban Development (HUD) considered alternative sites before redesignating a proposed site for middle-income housing as one for low-income housing it should have given determinative weight to environmental factors such as crowding low-income housing into a concentrated area and should not have considered the...
C programming, if you already answer this, please skip, thanks fill in ... /* In this...
C programming, if you already answer this, please skip, thanks fill in ... /* In this program, read stdin a line at a time, and print the longest line. If that line is longer than 30 characters, print it in the format first ten characters...middle ten characters...last ten characters. Note: The longest line can be quite long. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> #define BLOCKSIZE 100 char* readline() {    char* result = NULL;    int rsize;...
Please read clearly and answer with explanation Thanks! B ) Show how each of the following...
Please read clearly and answer with explanation Thanks! B ) Show how each of the following would affect the U.S. balance of payments. Include a description of the debit and credit items, and in each case identify which specific account is affected (e.g., imports of goods and services, IM; exports of assets, EXA; and so on). a). The U.S. central bank purchases $500 million worth of U.S. Treasury bonds from a British financial firm and sells pound sterling foreign reserves.
IN YOUR OWN WORDS-PEASE DO NOT COPY AND PASTE ) PLEASE READ-->DO NOT ANSWER QUESTIONS__> Please...
IN YOUR OWN WORDS-PEASE DO NOT COPY AND PASTE ) PLEASE READ-->DO NOT ANSWER QUESTIONS__> Please determine in each questions wether it is biased and which is unbiased for both A & B. How their examples do or do not create a bias. 1) A) Do you think obesity is the cause of cardiovascular diseases (CVD)? B) Why people don’t lose weight to decrease risk factors for cardiovascular diseases (CVD)? 2 A) Do you think High Blood Pressure is caused...
Simulation (Please read the scenario before answering the question. Also type your answer thanks) This is...
Simulation (Please read the scenario before answering the question. Also type your answer thanks) This is Becky, the nurse in the emergency Department. I am caring for Robert jones a 60-year-old African- American male. We admitted him at at 4:30   this morning. He reported increased shortness of breath and weakness.    His vitals were: blood pressure 80 over 62, R 30 pulse 164 and in a-fib. We gave him a 1000 milliliter bolus of sodium chloride to bring his blood pressure....
Please Read “How To handle difficult conversation”, and answer the following, Thanks! Difficult conversations — whether...
Please Read “How To handle difficult conversation”, and answer the following, Thanks! Difficult conversations — whether you’re telling a client the project is delayed or presiding over an unenthusiastic performance review — are an inevitable part of management. How should you prepare for this kind of discussion? How do you find the right words in the moment? And, how can you manage the exchange so that it goes as smoothly as possible? What the Experts Say “We’ve all had bad...
Please Read “How To handle difficult conversation”, and answer the following, Thanks! Case Study #1: Be...
Please Read “How To handle difficult conversation”, and answer the following, Thanks! Case Study #1: Be clear, direct, and unemotional Tabatha Turman, the founder and CEO of Integrated Finance and Accounting Solutions, a financial firm with both government and private sector clients, knew she had a problem with a certain employee. “He was a nice person and he worked long hours but his productivity was an issue,” she says. “He wasn’t right for the position he was in.” She and...
Please read the question carefully and then provide the answer thanks. Discussion Topic Choose a TCP/IP...
Please read the question carefully and then provide the answer thanks. Discussion Topic Choose a TCP/IP service, such as a web browser, email, file transfer, remote shell, DHCP, DNS, network time protocol, network address translation, etc. Important! Everyone should pick a different service, if possible, to keep the discussion fresh. In your original post, answer the following about the service you have chosen: How would you determine the IP addresses of your devices on your network? Success Hints You can...
Code in C# please. Write a program that will use the greedy algorithm. This program will...
Code in C# please. Write a program that will use the greedy algorithm. This program will ask a user to enter the cost of an item. This program will ask the user to enter the amount the user is paying. This program will return the change after subtracting the item cost by the amount paid. Using the greedy algorithm, the code should check for the type of bill. Example: Cost of item is $15.50 User pays a $20 bill $20...
Please answer do not use picture and handwriting, please typing word. copy other answer 2.State and...
Please answer do not use picture and handwriting, please typing word. copy other answer 2.State and Local Government face three fundamental fiscal choices . Please list these choices , and using an example in a specified government program , explain how these choices interact with each other , if at all 1 ) The correspondence principle provides an understanding of how the services ( or public goods ) of government may be organized and delivered . Please describe this principle...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT