File Input Question
I'm writing a program that inputs web logs from a file. I need though to split each part of the log into it's separate parts. What I can't remember is how to set which character to stop inputting for.
The default as you know is white space (I.E. each time a white space is reached in the file, it stops the stream into that variable and goes to the next variable, in my case the different variables of a struct.)
How do I change what that is. Like when I reach a ] in the file, it stops the input?
I hope that made sense.
EDIT - Also, I need it to look for different characters for the same run-through. How do I change it mid-way?
[684 byte] By [
Chrispy] at [2007-11-20 10:55:05]

# 3 Re: File Input Question
Sorry for the double post, but I didn't think it would be noticed if I didn't do this.
Here is the struct:
struct Logs
{
std::string IP_Address;
std::string More_Information;
std::string User_Information;
std::string Day_Time_Zone;
std::string Requested_Path;
int Status_Code;
double Bytes;
std::string Referral_URL;
std::string User_Agent;
};
Here is the function that inputs into the vector of this struct:
while (/*!In_File.eof()*/ a != 1)
{
Logs Inputted_Log;
In_File.get(Inputted_Log.IP_Address, 25);
In_File.get(Inputted_Log.More_Information, 25);
In_File.get(Inputted_Log.User_Information, 25);
In_File.get(Inputted_Log.Day_Time_Zone, 25, ' ] ');
In_File.get(Inputted_Log.Requested_Path, 25, ' " ');
In_File >> Inputted_Log.Status_Code;
In_File >> Inputted_Log.Bytes;
In_File.get(Inputted_Log.Referral_URL, 25, ' " ');
In_File.get(Inputted_Log.User_Agent, 25, ' " ');
Log_Vector.push_back(Inputted_Log);
a = 1;
}
and it's giving me this error for each .get line:
Error - o matching function for call to `std::basic_fstream<char, std::char_traits<char> >::get(std::string&, int)'
note - candidates are: typename std::basic_istream<_CharT, _Traits>::int_type std::basic_istream<_CharT, _Traits>::get() [with _CharT = char, _Traits = std::char_traits<char>]
With a few more notes after that for other candidates.
I have no idea what to do with that.
Also, I have .EOF in that while loop, but it wasn't working. When I had it as not EOF it was an infinite loop, when it was EOF it didn't even go into the while loop. Any suggestions?
# 5 Re: File Input Question
I'm writing a program that inputs web logs from a file. I need though to split each part of the log into it's separate parts.
Use PERL for that, not C++! ;) What I can't remember is how to set which character to stop inputting for. If you are reading into a string, using operator<<, you cannot set the delimitor. Either you read in the whole line and then use boost::regexp to separate it into parts (it is what I recommend doing), or you use ifstream::get function as RaleTheBlade recommended.
it's giving me this error for each .get line:Check the syntax: The first argument of get is a char*, not std::string. So you have to allocate a buffer big enough to hold the read in data. Also the last argument is a single char, not a string. What you put there (a string in single quotes) is not defined.