Creating a Program to Search an Index File Using the Command Line in Linux

Pages: 12
But the program5.cpp file is the one reading the data file and creating the index file, so I did

1
2
 
#include "program5.cpp"  


To include the variables from that file. Was this wrong?
Last edited on
How do you compile (aka build)?

Even though you have to reinvent the wheel, you could still ask yourself: "What does the grep do?"
I'm using Linux so I use

 
g++ -o program5Search program5Search.cpp


Doesn't grep search a file for a specified word, number, etc?
Ok, here's what I've done. I've added main back to the program5.cpp file, deleted the #include "program5.cpp" part from the prog5Search.cpp file, and I think I've declared all the needed variables in the prog5Search.cpp file. This has gotten rid of most of the errors, but I've still got one that I can't figure out.

1
2
3
/tmp/ccSbFaA4.o: In function `main':
prog5Search.cpp:(.text+0x15f): undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char> >&, Record const&)'
collect2: ld returned 1 exit status


Any ideas how I could fix this?
But the program5.cpp file is the one reading the data file and creating the index file, so I did
1) never include traditional implementation files

2) The whole point for your search program is to be separate from creating file. You should have 2 programs: one to create index file from data file and second to open index file and search for needed entry.
Ok, I've fixed that part, see latest comment for current issue.
Where is the implementation of the "print function"?

The g++ -o program5Search program5Search.cpp is nice, but I would:
g++ -std=c++11 -Wall -Wextra -o program5Search program5Search.cpp


Doesn't grep search a file for a specified word, number, etc?

Grep displays each line that contains the "word" (actually a regular expression).
You want to display each line that contains "id" (which is essentially a word).
Oops, yep that was it. It compiles now. However, when I run the search 12345 prog5.idx I get a "command not found error". I tried grep 12345 prog5.idx as well, but nothing is displayed?
Never mind, I'm dumb. Fixed it and it's working perfectly now. Thank you so much for being so patient and for all your help!
Topic archived. No new replies allowed.
Pages: 12