I have to write a program that reads in from a .txt file similar to
12345 Il 4350 (sales number, state abbreviation, amount)
for the most part I dont have an issue with this, however I have to read in the State abbreviation as separate characters and ultimately alphabetize them. I am having total brain block on how to read in the State Abbrev as separate characters.....any help would be appreciated

Recommended Answers

All 3 Replies

try declaring an empty STL style string. The concatenated each char to the end of the string. Store each string in an array and sort the array after input stops.

I have to write a program that reads in from a .txt file similar to
12345 Il 4350 (sales number, state abbreviation, amount)
for the most part I dont have an issue with this, however I have to read in the State abbreviation as separate characters and ultimately alphabetize them. I am having total brain block on how to read in the State Abbrev as separate characters.....any help would be appreciated

Not sure why you would want them as separate character variables instead of an array, but it seems easy enough. Just read it in with the >> operator.

ifstream ins;
    ins.open ("input.txt");
    char stateChar1, stateChar2;
    int salesNumber, amount;

    ins >> salesNumber >> stateChar1 >> stateChar2 >> amount;

If this isn't what you're looking for, you may need to elaborate.

I have figured out how to read them in separately, however I am to alphabetize them.....I am supposed to evaluate each character separately.....still a work in progress, thanks for you help thus far

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.