there are two text files, one called target.txt and template.txt i can only get my program to read in the text files.. im not sure how i can echo print them to the screen and format them to a table

please any help would be appreciated!

1. Reads the target pattern into an array "target[10][10]. To read the numbers, have the program skip over the text at the beginning of the file using the getline function.

2. Reads the template pattern into an array "temp[3][3]". Again, you will have to skip over the text at the beginning of the file to access only the numbers.

3. Echo prints both the target and template patterns to the screen using good formatting, with identifying titles.

thank you!!

using namespace std;

#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

void put_into_vector( ifstream& ifs, vector<int>& v )
{
string s;
getline( ifs, s );
istringstream iss( s );
copy( istream_iterator<int>( iss ), istream_iterator<int>(), back_inserter( v ) );
}

int main()
{
vector<int> line_1, line_2;

ifstream ifs( "target.txt" );

put_into_vector( ifs, line_1 );
put_into_vector( ifs, line_2 );

void put_into_vector( ifstream& ifs, vector<int>& v )
{
string s;
getline( ifs, s );
istringstream iss( s );
copy( istream_iterator<int>( iss ), istream_iterator<int>(), back_inserter( v ) );
}

int main()
{
vector<int> line_1, line_2;

ifstream ifs( "template.txt" );

put_into_vector( ifs, line_1 );
put_into_vector( ifs, line_2 );


system("pause");
return 0;
}


im not sure if this is right, at all, since i am a beginner

Recommended Answers

All 2 Replies

First, you must show us what code you have written so there is something to talk about. Please [thread=78223]Read This Before Posting[/thread]

--

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.