Think I'm Missing Something Here...

CMPC :: Computing :: Programming :: C++

Go down

Think I'm Missing Something Here...

Post by Unchained on Sat Feb 27, 2010 9:58 am

I cant seem to find my error even though I know it will be super simple. Any thoughts?

Code:
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

string BLOCK;

void SCAN1();


void main()
{
   cout << "Enter the set of letters.\n\n";
   cin >> BLOCK;
   SCAN1();
   cin.get();
}

void SCAN1()
{
ifstream file("DIC.TXT");
  if (file)
  {
    string line;
    while (line!="")
   {
      getline(file, line);
      if(line.find(BLOCK)!= string::npos)
     {
        cout << line << '\n';
     }
   }
  }
}
avatar
Unchained
Mod

Posts : 448

Back to top Go down

Re: Think I'm Missing Something Here...

Post by Admin on Sat Feb 27, 2010 9:28 pm

what's the error message?

_________________
avatar
Admin
Pirate King

Posts : 559

Back to top Go down

Re: Think I'm Missing Something Here...

Post by Corey on Sun Feb 28, 2010 2:15 am

I know it! "Using namespace std;" should go after "include <iostream>" and before "include <string>"


Last edited by Corey on Mon Mar 01, 2010 5:56 am; edited 1 time in total

_________________
-Corey Hoard

(Yes, I totally copied Paul's avatar. Or, at least attempted to.)
avatar
Corey
Mod

Posts : 462

Back to top Go down

Re: Think I'm Missing Something Here...

Post by Paul on Sun Feb 28, 2010 6:11 am

Code:
using namespace std;
should be able to go anywhere in the file. but if anything it should go after the includes, all the includes.

BTW: Horrible coding practices. Wink You should use parameters over globals when given the chance as should be easy to do in that code.
avatar
Paul
Pickaxe

Posts : 611

Back to top Go down

Re: Think I'm Missing Something Here...

Post by Corey on Sun Feb 28, 2010 7:59 am

Hmm. Well, as to the placement of using namespace std, Will was having a similar issue awhile ago, and moving the using up fixed it. So, at least on visual c++, I think it does matter.

_________________
-Corey Hoard

(Yes, I totally copied Paul's avatar. Or, at least attempted to.)
avatar
Corey
Mod

Posts : 462

Back to top Go down

Re: Think I'm Missing Something Here...

Post by Paul on Sun Feb 28, 2010 5:04 pm

It should go after all the includes though. I have NEVER had that line be a problem with the exception of forgetting it.
avatar
Paul
Pickaxe

Posts : 611

Back to top Go down

Re: Think I'm Missing Something Here...

Post by Corey on Sun Feb 28, 2010 6:10 pm

Huh. That's weird, because for Will it only worked if it was directly after "#include <iostream>"


Last edited by Corey on Mon Mar 01, 2010 5:56 am; edited 1 time in total

_________________
-Corey Hoard

(Yes, I totally copied Paul's avatar. Or, at least attempted to.)
avatar
Corey
Mod

Posts : 462

Back to top Go down

Re: Think I'm Missing Something Here...

Post by Unchained on Mon Mar 01, 2010 4:52 am

I always put it after all of my includes... Never had a single problem with it, I think its proper practice to do so...

If this were an intricate and multi source code project I wouldn't use it but there isn't much risk of poisoning in such a small project.

I don't get any compile errors, but during runtime after I enter the value to search for, it closes without an error.
avatar
Unchained
Mod

Posts : 448

Back to top Go down

Re: Think I'm Missing Something Here...

Post by Paul on Sat Mar 06, 2010 4:51 pm

If it's an error that only shows up when you run the program and does not show up in compile errors or warnings then is the perfect time to use a debugger and pray it's obvious. . .
avatar
Paul
Pickaxe

Posts : 611

Back to top Go down

Re: Think I'm Missing Something Here...

Post by Paul on Sat Mar 06, 2010 5:13 pm

Well, It doesn't even make it as far as your call to SCAN1.
The error I was receiving was this:
Code:

TestCoding(2105) malloc: *** error for object 0x10000b780: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Program received signal:  “SIGABRT”.
avatar
Paul
Pickaxe

Posts : 611

Back to top Go down

Re: Think I'm Missing Something Here...

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

CMPC :: Computing :: Programming :: C++

 
Permissions in this forum:
You cannot reply to topics in this forum