Just an question if its correct!

Its correct LINE: 3?


1
2
3
4
else if(c=='m' || c=='M') //c is a char
{
elr = elr + "01120 ";     //elr is an string //is it corect??? to use string = string + "text"? Cause it says its another letter than m and also the result is not correct. //Just, its correct???
}
No complier errors == elr == std::string == correct
Hi,

std::string has the operator+ defined, so yes you can concatenate strings with it :+)

Cause it says its another letter than m and also the result is not correct.


What do you mean by that? If elr was "Cosmin", then elr += "01120 " would be "Cosmin01120 "

Note the use of operator += , it's equivalent to what you had.

Edit:

Are you doing math with wide chars by any chance? If so, don't use a string literal - use an appropriate number or variable with a wchar type instead, not a std::string.
Last edited on
Then, i have an bigger problem, thanks for answer.
I cant say all in here, you have an e-mail?
NOTE: I really dosen't want to put my code here.
I am not going to use email. Why can't you put part of your code here? It's better to have replies from multiple people.
Meh, ok then.

This is my main.cpp
1
2
3

//Cutted code


and this is the ecry loop.cpp
1
2
3

//Another cutted code


And the problem is at main.cpp, at the line 37 (elr) its not getting the output, its says its other characters than in the encry loop.cpp are, how to fix it? (Run and you will see at "Result: " part)

EDIT: Also, as you can see, at else it give a long line as an error the character dosent introducet yet, it gived me a lot of those.
EDIT2: The program must make "text" in "t-e-x-t" and after to load all letters to make it in a long numbers, like as "00102 22002 20011 20112 " but it give the error.
Last edited on
Hi,

void eloop(char c, string elr)

This function is void, and none of the parameters are passed by reference, so calling the function effectively does nothing.

So change it to this:

void eloop(const char c, string& elr)

That way elr will have it's value changed.


But more important than that, there are some major changes to be made:

Don't use goto - use loops instead. goto leads to really bad code, unless you are an expert (There are advanced reason where one might need to use it)

The encry cpp file could be greatly improved using a different data container try std::map<char, std::string> You can use it to "lookup" a char and get it to return it's matching string.

http://www.cplusplus.com/reference/map/map/map/
http://www.cplusplus.com/reference/map/map/operator[]/
http://www.cplusplus.com/reference/map/map/at/

You can use the encryption map to make a decyrption map.

Also, make you life easier by not doing this:

if(d=="y" || d=="Y" || d== "Yes" || d=="yes" ||d=="YES" ||d=="YEs" ||d=="YEAH")

The problem is that it is not worth it to try and cater for every combination of spelling and upper / lower case.

Instead make use of the toupper function which converts a single char to uppercase. http://www.cplusplus.com/reference/cctype/toupper/?kw=toupper

It's a bit odd to ask whether one wants to write to a file when the other option is to end the program.

In future, if you have errors, post them here verbatim.

Good Luck !!
I changed w/ void eloop(const char c, string& elr), in .cpp and .h file
And it gived me this error:
1
2
3
||=== Build: Debug in PR Encrypt messages (compiler: GNU GCC Compiler) ===|
D:\Program Files (x86)\CodeBlocks\MinGW\include\stdlib.h|60|error: expected initializer before 'extern'|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|


How to use std::map<char, std::string> in my code?

Also, decry loop is not maked, i didnt found already a way to make it.

I dont want to get into toupper funtion, old story.

It's a bit odd to ask whether one wants to write to a file when the other option is to end the program. What do you wanted to mean? I stay bad with english, sorry.
Last edited on
I stay bad with english, sorry.


My English is poor


Don't worry, at least you know a reasonable amount of another language, which is a whole lot better than only knowing one language, and nothing of anything else :+) I have made some corrections to help you learn a little easier :+)

And it gived gave me this error:


Is the extern in the header file?

How to use std::map<char, std::string> in my code?


Did you read the links I posted, looked at the examples?

What do you wanted to mean?


What did I mean?


If the user chooses no the program ends - a drastic solution, maybe you could provide a means to write to the console instead of a file.

I have to go out soon - I may not reply for awhile, but there are plenty of others who can help out :+)

closed account (48T7M4Gy)
Utiliza română, dacă sa mai ușor , vă vom traduce . Încercați oricum .
I fixed it, i forget an ; at the header file.
1
2
3
4
5


//**Extreme face palm**


All is good now, thanks also for the other info!, its usefull! Thanks a lot man! :D
Glad we were able to help :)
@kemort
> Utiliza română, dacă sa mai ușor, vă vom traduce. Încercați oricum.
What are you trying to say??
closed account (48T7M4Gy)
It must have been bad because I got reported. Maybe this time to the police. I can hear sirens and pounding at the front door as we speak.
Topic archived. No new replies allowed.