User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 391,874 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,373 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:

C++ reading,writing,displaying a file?

Join Date: Jun 2005
Location: California
Posts: 92
Reputation: djbsabkcb is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
djbsabkcb's Avatar
djbsabkcb djbsabkcb is offline Offline
Junior Poster in Training

Help C++ reading,writing,displaying a file?

  #1  
Sep 6th, 2005
I am trying to write a program that reads in a file of numbers, writes to a file and displays the numbers in correct order. I don't fully understand how to read the file and pass that information into my class declarations in order to output before and after the swap. Below is my code so far: Help me understand this please?

 	

#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include <fstream>


using namespace std;


class Sort
{
	private:
		int size;
		int *prt;
		
	public:
		Sort();
		void Print();
		void Selection_Sort( int arr[], int size);
		void Swap ( int &x, int &y);
		
}

Sort::Sort
{
	int size = 0;
	int *ptr = 0;

}  // end of constructor

void Sort::Selection_Sort( int arr[],int size)
{
	int min =0;
	int check = 0;
	int i = 0;

		for ( check = 0; check < size - 1; check++)
		{
			min = check;
			for ( i = 0; i < size; i++)
				if ( arr[i] < arr[min])
					min = i;
		Swap(arr[check], arr[min]);  // call Swap function
		}   // end of for loop
	
}   // end of Selection Sort

void Sort::Swap(int &x, int &y)
{
	int temp;
	temp = x;
	x = y;
	y = temp;
	
} // end of Swap 

void Sort::Print(ostream &o, char * list)
{
		o << endl;
		o << list.Sort;
}


int main() 
{

	ifstream infile("abc.txt", ios::in)   // input file
	
		if (!infile)
		{
			cout << " File could not be opened. " << endl;
			exit(1);
		}
		
	ostream outfile("xyz.txt", ios::out)   // output file
		
		if (!outfile)
		{
			cout << " File could not be opened. " << endl;
			exit(1);
		}
		
	
	return 0;

}
Attached Files
File Type: cpp sort.cpp (1.2 KB, 5 views)
AddThis Social Bookmark Button
Reply With Quote  
All times are GMT -4. The time now is 6:56 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC