• Dev C++ issues
    20 replies, posted
im making a simple access program using DevC++, im using Cmd, and windows app....now when i go to make a get-line code to tell the commands....and i get this error. ISO C++ forbids comparison between pointer and integer in if(timecode == "play 1") here is my code so far: #include <cstdlib> #include <iostream> using namespace std; int main() { int passcode; cout << "Enter the passcode:"; cin >> passcode; if(passcode == 25506) { cout << "valid" << endl; } cin >> getcode; if(timecode == "play 1") { system("1.mp3"); } else { cin >> getcode; } system("PAUSE"); return EXIT_SUCCESS; } Any ideas to how to fix this?
Strings in C and C++ are arrays of characters terminated with a 0x00 byte. Arrays in C and C++ are pointers to regions of memory. (so when you write "array[i]", it's the same as "*(array+i)") You haven't defined the variable "timecode" anywhere. Technically, the compiler shouldn't allow this at all, but it looks like it's assuming timecode is an int. You probably want to declare it as a string object. Thus, you're comparing an int (timecode) with the [I]pointer[/I] to the region of memory at which the string is located. You need to use strcmp()/strncmp() (the latter is preferable, as it won't read past the end of the string if the null character is missing). Alternately, you could convert the null-terminated character array strings into C++ "string" objects, then use the comparison operators as you would normally.
[QUOTE=ROBO_DONUT;16105671]Strings in C and C++ are arrays of characters terminated with a 0x00 byte. Arrays in C and C++ are pointers to regions of memory. (so when you write "array[i]", it's the same as "*(array+i)") You haven't defined the variable "timecode" anywhere. Technically, the compiler shouldn't allow this at all, but it looks like it's assuming timecode is an int. You probably want to declare it as a string object. Thus, you're comparing an int (timecode) with the [I]pointer[/I] to the region of memory at which the string is located. You need to use strcmp()/strncmp() (the latter is preferable, as it won't read past the end of the string if the null character is missing). Alternately, you could convert the null-terminated character array strings into C++ "string" objects, then use the comparison operators as you would normally.[/QUOTE] oh, yea, i forgot to put the int timecode.......
By the way, there are many bad things in that code For starters, don't use system("PAUSE"); use std::cin.get();
[QUOTE=raccoon12;16114308]By the way, there are many bad things in that code For starters, don't use system("PAUSE"); use std::cin.get();[/QUOTE] uh, yea, but for some reason it gives me a shit load of errors if i put that in...i get like 340 errors about teh exact same line... anyways, i fixed it....
[QUOTE=mikehadley;16115469]uh, yea, but for some reason it gives me a shit load of errors if i put that in...i get like 340 errors about teh exact same line... anyways, i fixed it....[/QUOTE] It gives you errors because you're using "using namespace std;" The "::" operator is used for namespace resolution. If you use the "std::" prefix while you're already working in the std namespace, the compiler looks for std::std::cin.get(), which is incorrect. I recommend that you remove the line "using namespace std;" altogether and replace "cin", "cout", and "endl" with "std::cin", "std::cout", and "std::endl", respectively.
Once you do that, get the hell rid of DevCPP and go to Code::Blocks or MSVC EE. [editline]03:43PM[/editline] [url]http://www.jasonbadams.net/20081218/why-you-shouldnt-use-dev-c/[/url]
Better yet, vim, GCC, and binutils. :smug:
[QUOTE=ROBO_DONUT;16124215]Better yet, vim, GCC, and binutils. :smug:[/QUOTE] You're really not cool by giving newbies horrible advice. Stop it.
[QUOTE=nullsquared;16124346]You're really not cool by giving newbies horrible advice. Stop it.[/QUOTE] And you're not really cool for trying to turn this into a dev environment war.
[QUOTE=ROBO_DONUT;16124423]And you're not really cool for trying to turn this into a dev environment war.[/QUOTE] Are you really suggesting vim is more user friendly than an IDE? Because that is what this is about.
[QUOTE=jA_cOp;16124473]Are you really suggesting vim is more user friendly than an IDE? [/QUOTE] It is. :smug:
[QUOTE=jA_cOp;16124473]user friendly[/QUOTE] [quote=Linux is not Windows]This is a big one. It's a very big term in the computing world, "user-friendly". It's even the name of a particularly good webcomic. But it's a bad term. The basic concept is good: That software be designed with the needs of the user in mind. But it's always addressed as a single concept, which it isn't. If you spend your entire life processing text files, your ideal software will be fast and powerful, enabling you to do the maximum amount of work for the minimum amount of effort. Simple keyboard shortcuts and mouseless operation will be of vital importance. But if you very rarely edit text files, and you just want to write an occasional letter, the last thing you want is to struggle with learning keyboard shortcuts. Well-organized menus and clear icons in toolbars will be your ideal. Clearly, software designed around the needs of the first user will not be suitable for the second, and vice versa. So how can any software be called "user-friendly", if we all have different needs? The simple answer: User-friendly is a misnomer, and one that makes a complex situation seem simple. What does "user-friendly" really mean? Well, in the context in which it is used, "user friendly" software means "Software that can be used to a reasonable level of competence by a user with no previous experience of the software." This has the unfortunate effect of making lousy-but-familiar interfaces fall into the category of "user-friendly". [/quote] Lousy, but familiar.
[QUOTE=ROBO_DONUT;16124577]Lousy, but familiar.[/QUOTE] Agreed. I hate taking my hands off the keyboard. Wears me out.
[QUOTE=ROBO_DONUT;16124423]And you're not really cool for trying to turn this into a dev environment war.[/QUOTE] OK, let's think through this rationally. We have a newbie, on Windows, using DevCPP. Is it a better idea to: A) tell him to use Code::Blocks or MSVC EE or B) tell him switch to Linux and use vim, a non-graphical IDE that uses a completely different interface :downs:
[QUOTE=nullsquared;16125542]OK, let's think through this rationally. We have a newbie, on Windows, using DevCPP. Is it a better idea to: A) tell him to use Code::Blocks or MSVC EE or B) tell him switch to Linux and use vim, a non-graphical IDE that uses a completely different interface :downs:[/QUOTE] You just type words. Notepad++ would be a good vim substitute for Windows.
[QUOTE=nullsquared;16125542]tell him switch to Linux and use vim, a non-graphical IDE that uses a completely different interface[/QUOTE] I didn't say anything about Linux. All of this software is available for Windows. Anyway, I was kidding. Hence the ":smug:". I don't want anyone to go and switch development environments if it's working for them.
yea, i got all these from watching yotube movies......and after 2 hours i kind of got it....... Altho, not quite familier with Windows Appications yet.....Im great with Command Console tho.
[QUOTE=ROBO_DONUT;16125679]I didn't say anything about Linux. All of this software is available for Windows. [/quote] OH, YES. Use vim on WINDOWS instead of MSVC, GREAT IDEA! [quote] I don't want anyone to go and switch development environments if it's working for them.[/QUOTE] No, it's not working for him. He should switch to Code::Blocks or MSVC.
[QUOTE=nullsquared;16126277]OH, YES. Use vim on WINDOWS instead of MSVC, GREAT IDEA![/QUOTE] Actually that'd be a way better idea if you're already used to vim on Linux rather than switching to a completely different and thus less efficient dev environment :) Now the OP isn't used to either, so I'm not sure why ROBO and PvtCupcakes bother, but otherwise that point would apply.
[QUOTE=nullsquared;16126277]OH, YES. Use vim on WINDOWS instead of MSVC, GREAT IDEA![/QUOTE] Chill. It's a matter of personal preference. I use both MSVC and vim/MinGW for programming in Windows. Each works fine.
Sorry, you need to Log In to post a reply to this thread.