Click to See Complete Forum and Search --> : Function Error
glen_4455
May 9th, 2008, 09:11 AM
Hallo all.
I have a function that I got error when I compiled, I really do not know how to cope it.
I have attach the code, and I was wondering if there is anyone would be able to help me..
The error message is:
error: stray '/342' in program
stray '/200' in program
...
error: no matching function far call to std::basic<char, std::char_traits<char>, ...
It get error on this code
int wordlen = x.find(" ");
I really need help with that as my assignment is due soon.
Thanks
S_M_A
May 9th, 2008, 09:15 AM
What's the error?
Richard.J
May 9th, 2008, 09:25 AM
line 8: wordlen = x.find(“ “);
does not contain valid characters.
S_M_A
May 9th, 2008, 09:25 AM
So you have some invalid characters (that are invisible) in your file. Go to the line that have a strange character. Type that line again on line before the offending line, mark the offending line and delete it.
Edit: Yes Richard is right, you should use " not “ (probably cut&paste from word or similar editor?)
glen_4455
May 9th, 2008, 10:06 AM
Hallo S_M_A,
Thanks for your help, however, I am still have a problem with my codes.
I make a menu program which is have 3 choices. 1st and 3rd choices in run well, whereas my 2nd choices it is not run well.
The 2nd choices is pig-latin translation. Could you help me to see through the code and fix it up?
I make 3 files, those are menu.h; menu.cpp; and menuApp.cpp
Richard.J
May 9th, 2008, 10:29 AM
what exactly is not working?
glen_4455
May 9th, 2008, 10:42 AM
the one is not working is the pig latin..
When I enter the string for example, "hello", the program does not give the pig-latin translation of it. (like no response..)
I am really stuck with that...
Paul McKenzie
May 9th, 2008, 11:18 AM
the one is not working is the pig latin..
When I enter the string for example, "hello", the program does not give the pig-latin translation of it. (like no response..)
I am really stuck with that...
Please read this first:
Now tell us what exactly have you done to solve the problem.
Have you used the debugger? If not, have you used output statements to see what is the problem? If you have done these, what results did you see? What was unexpected?
All of these issues are first tackled by you. If you're learning programming, a mandatory part of programming is learning how to debug your own code. Just handing off code to us and saying "what's wrong" misses the whole point of learning the proper ways to find out for yourself the problems with code.
I'm stating this, since I see too many posts where it is obviously a homework or homework-like assignment, where code is just handed off to us to "solve" if it doesn't run correctly, with no apparent effort on the original poster to attempt to diagnose the problem (no debug statements, no use of a debugger, no analysis as to what part of the code behaved differently than expected, etc.).
If you have attempted to debug this, please state what you have done in this regard.
Regards,
Paul McKenzie
glen_4455
May 9th, 2008, 06:32 PM
Thanks Paul,
However, i do not know how to use debugger and never use it before. Wondering if you can show me to debug my program..
I just compile my codes using g++ -Wall -g menuApp.cpp -o menuExe
and then running gdb menuExe, and after that gdb run
The program was running and when I select 2nd choices, it produces same output.. (nothing happens)
Paul McKenzie
May 9th, 2008, 06:51 PM
However, i do not know how to use debugger and never use it before. Wondering if you can show me to debug my program..Even if you didn't know how to use a debugger, there are ways to solve these problems.
What part of the code do you think is the problem? Wherever that is, you put output statements to see what the values of certain variables are. If they are not what you expected, then you place the output statements somewhere else, inspect the code by hand, or place more output statements to display what other variable values are. Things like outputting the value of loop counters, intermediate values, using the variout cout and printf() functions should be used.
These are all things that you must know how to do, regardless of whether you know how to use the debugger or not. These old but successful techniques are used in any high-level language, whether it's C++, C, Pascal, Java, Fortran, or even COBOL. Even in some OS'es (like Windows), you have an OutputDebugString() available to show diagnostic messages.
This is not aimed at you, but I get frustrated with the numerous number of new posters learning C++ that have shown absolutely no effort in doing the simplest things to debug their code -- not even a simple printf() statements to see what the value of various variables in their programs.
When I first learned programming over 20 years ago, it was a requirement to solve your own problems, and only go to the tutors if you have shown what you've done to attempt to solve a problem that you were having (if the problem was still unsolved). No way could you say "here is my program, I run it, it does x when it should do y, what's wrong?"
All of these techniques I mentioned are not the most modern (knowing how to use the debugger is the best way), but they do work. When the first interactive debuggers were introduced some time ago, it made all of the work of using printf()'s somewhat obsolete, but never so obsolete that they can not be used.
Another side issue in seeing what effort you've made in solving the problem is to see if you were the one who wrote the code, and not just lifted it from a friend or a web-site. If you truly wrote the code, you should understand how each part of the code works or should work. If there is a bug, you know what parts of the code could be causing the problem. Many times people post code that their friend wrote, and they have no idea what's wrong. IMO, those types of posters shouldn't be helped, even if they are following the rule of posting code.
Regards,
Paul McKenzie
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.