0

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

Edited by milanna1992: n/a

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by milanna1992
0

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]

Edited by griswolf: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.