Think I'm Missing Something Here...
4 posters
CMPC :: Computing :: Programming :: C++
Page 1 of 1
Think I'm Missing Something Here...
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';
}
}
}
}
Unchained- Mod
- Posts : 448
Re: Think I'm Missing Something Here...
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- Mod
- Posts : 462
Re: Think I'm Missing Something Here...
- Code:
using namespace std;
BTW: Horrible coding practices. You should use parameters over globals when given the chance as should be easy to do in that code.
Paul- Pickaxe
- Posts : 611
Re: Think I'm Missing Something Here...
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- Mod
- Posts : 462
Re: Think I'm Missing Something Here...
It should go after all the includes though. I have NEVER had that line be a problem with the exception of forgetting it.
Paul- Pickaxe
- Posts : 611
Re: Think I'm Missing Something Here...
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- Mod
- Posts : 462
Re: Think I'm Missing Something Here...
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.
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.
Unchained- Mod
- Posts : 448
Re: Think I'm Missing Something Here...
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. . .
Paul- Pickaxe
- Posts : 611
Re: Think I'm Missing Something Here...
Well, It doesn't even make it as far as your call to SCAN1.
The error I was receiving was this:
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”.
Paul- Pickaxe
- Posts : 611
CMPC :: Computing :: Programming :: C++
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|