Hi,
I have a file with the format
//////////
{blkid:= 10000}
dfd dfd
dfdfdfd
dfd dfd
{blkid:= 10001}
dfd fddd
gdfd dd
dfdd
ere
///////
I want to set '{' as a delimiter and read everything between into a
std::string.
I checked out getline but it expects a "size", in my case I dont know
how big
will the buffer be so how should I solve this problem. I have attached
a sample code which compiles but does not give me the string I expect.
Can you help.
Thanks.
Kapil
// semantics_of_da ta.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ifstream sample("sample. dat",ios::in);
ifstream outfile("temp.d at",ios::out) ;
char buf[10];
std::string sample_buf;
if(!sample || !outfile)
{
exit(0);
}
while(!sample.e of())
{
sample.getline( const_cast<char *>(temp_buf.c_s tr()),30,'{');
outfile << temp_buf;
}
gets(buf);
return 0;
}
I have a file with the format
//////////
{blkid:= 10000}
dfd dfd
dfdfdfd
dfd dfd
{blkid:= 10001}
dfd fddd
gdfd dd
dfdd
ere
///////
I want to set '{' as a delimiter and read everything between into a
std::string.
I checked out getline but it expects a "size", in my case I dont know
how big
will the buffer be so how should I solve this problem. I have attached
a sample code which compiles but does not give me the string I expect.
Can you help.
Thanks.
Kapil
// semantics_of_da ta.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ifstream sample("sample. dat",ios::in);
ifstream outfile("temp.d at",ios::out) ;
char buf[10];
std::string sample_buf;
if(!sample || !outfile)
{
exit(0);
}
while(!sample.e of())
{
sample.getline( const_cast<char *>(temp_buf.c_s tr()),30,'{');
outfile << temp_buf;
}
gets(buf);
return 0;
}
Comment