i am working with data files in C++ and my problem is i have to read in a list a names form two different data files then output them into a third data file in alphabetical order. I have to alphabetize them by assigning them ascII values.
I am having trouble assigning ascii to the first letter of the string variable. im not sure how to do this. i declared my variables then tried to assign the ascii values but its not working
heres what i have
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
//declare variables
string name_1, name_2;
int i ;
char a ;
//declare input data files
ifstream data_1;
ifstream data_2;
//declare output data files
ifstream output;
//open data files
data_1.open("P:\\C++\\data_1.dat");
data_2.open("P:\\C++\\data_2.dat");
//if fails
if(data_1.fail() || output.fail())
{
cout<<"Error with File"<<endl;
return 0;
}
data_1>>name_1;
//data_2>>name_2;
while(!data_1.eof() && !data_2.eof())
{
cout<<name_1<<endl;
//cout<<name_2<<endl;
//='name_1'
char name_1;
cout<<name_1<<endl;
data_1>>name_1;
//data_2>>name_2;
Alphabetical order using ASCII valuesusing ASCII to alphabetize a list of names
Page 1 of 1
1 Replies - 6118 Views - Last Post: 29 February 2008 - 01:11 AM
Replies To: Alphabetical order using ASCII values
#2
Re: Alphabetical order using ASCII values
Posted 29 February 2008 - 01:11 AM
Welcome to Dream In Code
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|