Need a geek? Geeks to Go offers free, quality tech support -- in terms anyone can understand. Volunteers are waiting to help, friendly, technology experts who have knowledge to share, and enjoy helping others. Feel free to browse the site as a guest. However, you must log in to reply to existing topics, or to start a new topic of your own. Other benefits of joining include richer forum features, and removal of all advertising. Learn more in our Welcome Guide Infected? Malware and Spyware Cleaning Guide. What are you waiting for? Click here to join for free today!
C++ - two int variables can't be compared., invalid operands of types `int' and `<unknown type>'
IO-error
post Nov 13 2009, 04:14 PM
Post #1


Member
***
Posts: 254
From: the Netherlands
OS: WinXP PRO SP2 [Version 5.1.2600]



Hi all.

/offtopic
I used to be VBS nerd and made a lot of vbs scripts that helped me in my daily life.
One example is a vb-script that saves a picture with one press of a (logitech G15 macro-)key.
But now with the coming of Windows 7 and the disappearance of VBS overall, I need to learn C++.
/offtopic

This brings me to a problem in the source code.
I could post all files you need to create my program, but that's a bit clumsy, so I'll just give the relevant pieces of code and the includes I used.
The errorneous line is marked with stars for your convenience.

CODE
#include <windows.h>
#include <stdio.h>
#include <cstring>

#include <iostream>
#include <fstream>
#include "InputBox.h" //you probably don't have this file.

string s = result2;

int countVowels(char result2[]);
{
    int count = 0, k = 0;
    while (result2[k] != '\0');
    {
          if (result2[k] == '\\');
          {
              count++;
          }
          k++;
    }
    return count;
}
int i = 0;
(line 108)******** for (i < count);********
         (
          i++;
          int position = s.find("\\");
          s.replace(position, 1, "\\\\");
          }


Error messages:
108 F:\%path%\CInputBoxTest.cpp invalid operands of types `int' and `<unknown type>' to binary `operator<'
108 F:\%path%\CInputBoxTest.cpp expected `;' before ')' token
110 F:\%path%\CInputBoxTest.cpp expected `)' before ';' token
111 F:\%path%\CInputBoxTest.cpp expected primary-expression before "int"
111 F:\%path%\CInputBoxTest.cpp expected `)' before "int"


I understand I can't use < or any other >=! for comparing the two integers, but what do I use?
If you need more code, just ask me, I'll then add the .h and full .cpp.

***UPDATE after writing***
Whilst writing this (or typing, whatever), I googled across GetNumbers and GetBig... I might get into that, but if somebody has a solution to my initial problem, I'll be glad to hear it.

TIA & greet - I/O-Error
Go to the top of the page
 
+Quote Post
 
Start new topic
Replies (1 - 9)
mpascal
post Nov 14 2009, 03:19 PM
Post #2


Math Nerd
Group Icon
Posts: 2,560
From: Canada
OS: Windows 7 Professional, Ubuntu 9.10



Hi IO-error,

You can use < and > for comparing two integers. From what I can see, the function you are creating doesn't recognise what the variable "count" is.
Go to the top of the page
 
+Quote Post
IO-error
post Nov 14 2009, 08:14 PM
Post #3


Member
***
Posts: 254
From: the Netherlands
OS: WinXP PRO SP2 [Version 5.1.2600]



When I use either < or >, I get the same errorcode.
Line 108 - invalid operands of types `int' and `<unknown type>' to binary `operator<'

The sad thing is, I can't figure out why it says "count" is unknown.
I'll clean out the code and post it here ASAP.


This post has been edited by IO-error: Nov 14 2009, 08:38 PM
Go to the top of the page
 
+Quote Post
mpascal
post Nov 14 2009, 09:09 PM
Post #4


Math Nerd
Group Icon
Posts: 2,560
From: Canada
OS: Windows 7 Professional, Ubuntu 9.10



Hi,

Try posting the whole code so I can take a look, or at least all the code up until line 115 or so.
Go to the top of the page
 
+Quote Post
IO-error
post Nov 15 2009, 01:18 AM
Post #5


Member
***
Posts: 254
From: the Netherlands
OS: WinXP PRO SP2 [Version 5.1.2600]



Thank you for your time mpascal.

I managed to fix the code by looking on the internet for clues all day long and trying diverse things....
I'm glad I can finally go to bed now.


This is how I fixed the faulty part.
I hope this helps other people who had the same problems.

google-tags: string replace all backslash C++

CODE
using std::string;
      stringstream ss;
      string s;
      ss << result2;
      ss >> s;

   int position = s.find( "\\" ); // find first space

   while ( position != string::npos )
   {
      s.replace( position, 1, "\\\\" );
      position = s.find( "\\", position + 2 );
   }


This post has been edited by IO-error: Nov 15 2009, 11:58 AM
Go to the top of the page
 
+Quote Post
mpascal
post Nov 15 2009, 02:16 PM
Post #6


Math Nerd
Group Icon
Posts: 2,560
From: Canada
OS: Windows 7 Professional, Ubuntu 9.10



Hi,

Glad you fixed it thumbsup.gif. Just out of curiosity, may I ask what the problem with the code was?
Go to the top of the page
 
+Quote Post
IO-error
post Nov 15 2009, 02:38 PM
Post #7


Member
***
Posts: 254
From: the Netherlands
OS: WinXP PRO SP2 [Version 5.1.2600]



I am sure the problem in first post was that I didn't use three parameters in s.replace().
As for the problems I had afterwards, it was just logics errors, which I had to crush my mind for to understand it.

Example, I didn't let the count of position slide after the position it has already been.
So basically:
s = "C:\ut2004\system\ut2004.exe"
and s needs to get all his \ replaced by \\.
The int_position told find() where to replace it and how many times.
But as the counter for replacing it went on, the counter for position remained the same.
thus ending with this:
s = "C:\\\\\\\\\\ut2004\system\ut2004.exe"

So when I finally did crack it I was very happy.
The program is now completed and dubbed KeyAdder 0.5 Beta.
The final release is not yet scheduled, but if you (google-guests) can't wait, contact me.
Go to the top of the page
 
+Quote Post
mpascal
post Nov 15 2009, 02:47 PM
Post #8


Math Nerd
Group Icon
Posts: 2,560
From: Canada
OS: Windows 7 Professional, Ubuntu 9.10



Very interesting, thank you for that smile.gif
Go to the top of the page
 
+Quote Post
IO-error
post Nov 15 2009, 04:11 PM
Post #9


Member
***
Posts: 254
From: the Netherlands
OS: WinXP PRO SP2 [Version 5.1.2600]



Thank you for your interest too.
Your post made me see that the variable "count" was not recognized, so I thought of merging the "find("\")"-function and "replace(npos,"\","\\")"-function into one function. And that, including the correct counting of npos, helped me out.

Thnx again for the kickstart.
Go to the top of the page
 
+Quote Post
mpascal
post Nov 16 2009, 01:10 AM
Post #10


Math Nerd
Group Icon
Posts: 2,560
From: Canada
OS: Windows 7 Professional, Ubuntu 9.10



Not a problem, glad I could help you out thumbsup.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Time is now: 22nd March 2010 - 09:39 AM

Advertisements do not imply our endorsement of that product or service. The forum is run by volunteers who donate their time and expertise. We make every attempt to ensure that the help and advice posted is accurate and will not cause harm. However, we do not guarantee that they are accurate and they are to be used at your own risk. All trademarks mentioned on this page are the property of their respective owners.

© Geeks to Go, Inc. | All Rights Reserved | Privacy Policy | Advertising