You posted code, which is good, but didn't tell us whether the code works or what the input file should be, how to use your program, which part of the code to concentrate on, stuff like that.
I'm not entirely sure what you want, but I think that this is a line in input file:
copy_input "The String Will Be Here"
and which you'll read in and store as a string. The you want to extract this part:
The String Will Be Here
Set up a function that does this:
string ExtractSubstring (string longstring)
// longString is a string that contains beginning and ending quotes.
// return value: the substring within longString that is between the two quotes.
So find the indexes of the two quotes
0 1 2 3
0123456789012345678901234567890123456789
copy_input "The String Will Be Here"
In this case it's 11 and 35, so return the substring from 12 to 34.
The find and substr functions from the string library can come in handy here.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
You can use the indexes, but you can also use flags.
First try to read in a file. Then check for the first quote ( " ) and
if found read in the data until another quote ( " ) is found.
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
Hello VernonDozier,
That syntax is in my language that i'm developing.
Thanks,
Nathan Paulino Campos
Right, but I am assuming you are developing a function along the lines of what I suggested and you are having trouble. I didn't see that function in the code you posted and I didn't know what worked and didn't work in the code and where you wanted us to look, stuff like that. And I'm still just assuming that you are having problems writing a function along the lines of what I suggested. You haven't actually said that. So what precisely is the question?
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
But how i can do this?
We cross-posted. Does "this" refer to the function I am suggesting or do you want to read in from the file and keep track of quotes as you're reading in, which seems to possibly be the case from your earlier code, and hence there's no string to parse?
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
I want to read the thing that are in the quotes and use this thing that is inside the quotes as a variable(char*), only this.
Read from the file a line at a time using getline, then extract the string using the function I suggested in post number 2.
ifstream ins;
// initialize ins with filename.
string wholeLine;
getline (ins, wholeLine, '\n');
string partInQuotes = ExtractSubstring (wholeLine);
You'll need to write the function. use find and substr from string to do so.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
Read from the file a line at a time using getline, then extract the string using the function I suggested in post number 2.
ifstream ins;
// initialize ins with filename.
string wholeLine;
getline (ins, wholeLine, '\n');
string partInQuotes = ExtractSubstring (wholeLine);
You'll need to write the function. use find and substr from string to do so.
Didn't notice you wanted a char*, not a string to be returned. Same idea though. You can change a string to a char* and vice-versa. Use c_str (). http://www.cplusplus.com/reference/string/string/c_str/
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711