Trouble reading in Chars, adding them together as a string with If Statements.

I'm writing a program and I'm in the final stage from it. I'm reading in these forumlas from a file that have letters and numbers. There's some cases where I need to add 2 of the characters together to form a string such as "Au" that I can then use to search through an array for corresponding information.

The issue is, adding them as chars into a string doesn't work properly. But if I change them to strings and add them to be equal to another string variable, it works. But I have if statements that rely on what letter has been read in and if it's uppercase or lower case. They only activate if they are chars, and have errors when made strings.

Essentially, I can get them to add together when I have the variables a and b as strings, but then the if statements won't work. If I have a and b as chars, the if statements would work, but then I can't add them together as a string to search properly.

 
https://pastebin.com/CSEPadDk 
¿so what part of those 179 lines should we look at?

1
2
3
std::string s;
s += a;
s += b;
so what part of those 179 lines should we look at?

The relevant part obviously

You can't really add char variable types together. You could make an array of characters if you want, but I don't see why you can't use the string for if statements. You may want to simply rethink how the if statements operate.
So when I read in like two characters such as "Au" I need to insert them into a search to find them in another array. The thing is when I make a and b from Chars to a string to add them together and have an if statement like if(ifupper(a)) which is required for me to distinguish some of the things I'm reading in, it doesn't work. Is there another way I can use ifstatements to distinguish from upper and lower cases?
Do you know you can get a C style string from a std::string?

http://www.cplusplus.com/reference/string/string/c_str/
The thing is when I make a and b from Chars to a string to add them together and have an if statement like if(ifupper(a)) which is required for me to distinguish some of the things I'm reading in, it doesn't work.


In that if statement, is "a" the string? You want to deal with individual characters, so you'd use the string as an array:

if(ifupper(a[0]))

And you can run through all elements in a loop with the condition being a.size()
Not necessarily. I'm reading in from a file one at a time using the peek function with b as peek and a as what I initially read in. Depending on what b is, I'm going to use if statements to do things where I may have to add a and b together. But when theyre chars, they won't add. So I can make them strings so they will add together into a new string correctly, but then the if statements don't work correctly.
You could take everything in into "a" as a string rather than work with them individually. Or, you could make two if statements, one to handle char and another to handle strings
Well my if statements have to be depended on what I'm reading in. I'm reading in puncts and digits as well. I could do an array of a as a string, but I tried something similar with an array string and it wouldn't work with my if statements unless it was a char.
Which if statements in particular aren't working? Post them here
All of them really. Everytime I change a and b to strings so I can actually add them, the if statements keep getting errors unless they're chars
I've already showed you how to add `a' and `b' if they are char
zapshe showed you how to work your ifs with a std::string


> the if statements keep getting errors unless they're chars
I cannot work with imaginary code
show the lines that caused the errors, along with the error message verbatim
Topic archived. No new replies allowed.