Hi there,

I'm working with a file. I want to write a code that returns a particular string located somewhere in the file. I have the starting position of the desired string and it's length so I thought that i can use substr(starting position, length of the string) but it doesn't work anybody has any idea to help me.

I really appreciate it,

Recommended Answers

All 4 Replies

you have the starting position and the length of the string, so just start reading character by character from the starting position length number of times.

I think i could have done that if i had a string, by writing something like this:

string t = "";
for(int i=start;i<start+length;i++){
            t+=sentence[i]; }

But in the Code that I'm writing, the larger string that i called it sentence in above sample, hasn't been specified as a string.

I might not be on a right track. I'm new to C++ (and programming in general). SO could you please explain it to me how can i read it character by character as you said.

what is the type of the variable sentence

it's a string.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.