this may not be the most efficient manner to do this, but here is what i would do:
read the file into a buffer of say 256/512 chars, the search for the sub-string linearly.
There is probably a std method that would solve the problem but you could just extract char by char and use a loop of if statements to check if all the chars match.
Thank's.
but how i can solve it?
when i use JLBorges's way errors occurring.please help me it is very important.each run i would opening the file 100 time.
my file is in below form:
i'm using VS for programming.
error:namespace "std" has no member "vector"
searching for patterns i have in table.
return true(exist)/false(not exist).
dear JLBorges i'm beginner .
>Why can't it be read once and then its contents held in memory?
how can I do this?
one table:
i want to search for example (dnnssttoor OR dnnsstt) if this word dos not exist search function return false and if exist return true, also each time running program this give me a different table from previous
a a r d w o l v e s
a b a n d o n e e s
a b a n d o n i n g
a b a s e m e n t s
a b a s h m e n t s
a b a t e m e n t s
a b a t - j o u r s
A b b o t s f o r d
a b b o t s h i p s
a b b r e v i a t e
The exact word 'dnnssttoor'?
A word containing the substring 'dnnssttoor'?
A word containing exactly one 'd', two 'n', two 's', two 't' etc.?
A word containing at least one 'd', two 'n', two 's', two 't' etc.?
And what does this mean: 'each time running program this give me a different table from previous'?
> i want to search for example (dnnssttoor)
for 4th column at below :
i want search for :dnnssttoor OR dnnssttoo OR dnnsstto OR dnnsstt...
OR d.
>And what does this mean: 'each time running program this give me a different table from previous'?
at below you see two different table.
********************
a a r d w o l v e s
q b a n d o n e e s
e b a n d o n i n g
r b a s e m e n t s
j b a s h m e n t s
a b a t e m e n t s
z b a t - j o u r s
b b b o t s f o r d
e b b o t s h i p s
w b br e v i a t e
********************
a b d i c a t i n g
v b d i c a t i o n
s b d i c a t o r s
xb d o m i n a l s
m b d o m i n o u s
n b d u c t i o n s
y b e r d e v i n e
d b e r d o n i a n
s b e r r a t i n g
a b e r r a t i o n
#include <vector>
#include <fstream>
#include <string>
// read all the lines in the file into a vector
std::vector<std::string> lines_in_file( constchar* path_to_file )
{
std::vector<std::string> result ;
std::ifstream file(path_to_file) ;
std::string line ;
while( std::getline( file, line ) ) result.push_back(line) ;
return result ;
}
int main()
{
constchar* const path = "/usr/share/dict/words" ;
const std::vector<std::string> words = lines_in_file(path) ;
}
Now, the char at column four of line 134 (zero-based) is: words[134][4].