473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Hi can any one expalin me this piece of code

62
Hi can any one expalin me this piece of code
In this code line is used for taking the input stream as line input stream.
Please explain me Can I use getline() instead of line.
When I am using the above code I am fetting errors like
line undeclared.

Please help me to resolve my problem


void get_name_token ( strstream &line, ostrstream & output )
{
// Set line stream for input operations.

line.setf(ios::in);

// "Stop" is the char that immediately follows an extracted token
// part in the input stream. If "Stop" is a tab, newline, or EOF
// character, it indicates the end of a token. I give "Stop" an
// arbitrary initial value that is definitely not a delimiter.

char Stop = 'a';

// Eat leading white space and check "Stop" for end of token.
// Quit loop when "Stop" signals the end of a token.

while ( line >> ws , (Stop != '\t' && Stop != '\n' && Stop != EOF ))
{
line.get ( *output.rdbuf(), ' ' ); // get next token part.

Stop = (char)line.peek(); // Check next char for end of token

if ( Stop == ' ' )
{
// Might be end of token or just an embedded space.
// get the "Stop" character to advance the streambuf ptr.

line.get ( Stop );

// If the next character is a space then its the end of the
// token, so we set Stop to EOF to break the while loop.

if ( line.peek() == ' ' )
{
Stop = EOF;
}
else
{
output << Stop;
}
}
}
output << ends;
}



vendor_map_tb_t init_vendor_table( char* vendor_file_name )
{
ifstream vendor_instream ( vendor_file_name );

if ( vendor_instream )
{
// Allocate the vendor_table;

vendor_map_tb_t vendor_table = new gtb(string_t, vendor_map_t)( &stringless, &stringequals );

// eat initial leading blank lines and whitespaces, then
// check for EOF. Loop until the file is empty.

while ( vendor_instream >> ws, !vendor_instream.eof() )
{
// Declare "line" stream and set it for output operations.

strstream line;
line.setf(ios::out);

// Get a line from the vendor file stream.

vendor_instream.get ( *line.rdbuf(), '\n' );
line << ends;

if ( line.peek() == EOF || line.peek() == '#' )
{
// The line is blank or a comment, so ignore it and start
// again with the next line.

line.clear ();
vendor_instream >> ws;
}
else
{
int count = 0;
ostrstream names[3];

// Get three tokens from the line.

while ( count < 3 ) get_name_token ( line, names[count++] );

// Ignore the rest of the line. This allows us to extend the
// the number of tokens on a line in some future release without
// breaking a translator that expects three tokens on the line.

line.clear();
Oct 5 '06 #1
2 2157
r035198x
13,262 8TB
Hi can any one expalin me this piece of code
In this code line is used for taking the input stream as line input stream.
Please explain me Can I use getline() instead of line.
When I am using the above code I am fetting errors like
line undeclared.

Please help me to resolve my problem


void get_name_token ( strstream &line, ostrstream & output )
{
// Set line stream for input operations.

line.setf(ios::in);

// "Stop" is the char that immediately follows an extracted token
// part in the input stream. If "Stop" is a tab, newline, or EOF
// character, it indicates the end of a token. I give "Stop" an
// arbitrary initial value that is definitely not a delimiter.

char Stop = 'a';

// Eat leading white space and check "Stop" for end of token.
// Quit loop when "Stop" signals the end of a token.

while ( line >> ws , (Stop != '\t' && Stop != '\n' && Stop != EOF ))
{
line.get ( *output.rdbuf(), ' ' ); // get next token part.

Stop = (char)line.peek(); // Check next char for end of token

if ( Stop == ' ' )
{
// Might be end of token or just an embedded space.
// get the "Stop" character to advance the streambuf ptr.

line.get ( Stop );

// If the next character is a space then its the end of the
// token, so we set Stop to EOF to break the while loop.

if ( line.peek() == ' ' )
{
Stop = EOF;
}
else
{
output << Stop;
}
}
}
output << ends;
}



vendor_map_tb_t init_vendor_table( char* vendor_file_name )
{
ifstream vendor_instream ( vendor_file_name );

if ( vendor_instream )
{
// Allocate the vendor_table;

vendor_map_tb_t vendor_table = new gtb(string_t, vendor_map_t)( &stringless, &stringequals );

// eat initial leading blank lines and whitespaces, then
// check for EOF. Loop until the file is empty.

while ( vendor_instream >> ws, !vendor_instream.eof() )
{
// Declare "line" stream and set it for output operations.

strstream line;
line.setf(ios::out);

// Get a line from the vendor file stream.

vendor_instream.get ( *line.rdbuf(), '\n' );
line << ends;

if ( line.peek() == EOF || line.peek() == '#' )
{
// The line is blank or a comment, so ignore it and start
// again with the next line.

line.clear ();
vendor_instream >> ws;
}
else
{
int count = 0;
ostrstream names[3];

// Get three tokens from the line.

while ( count < 3 ) get_name_token ( line, names[count++] );

// Ignore the rest of the line. This allows us to extend the
// the number of tokens on a line in some future release without
// breaking a translator that expects three tokens on the line.

line.clear();
If you post the code using code tags, it will be easier to read it
Oct 5 '06 #2
srikar
62
Hi when I am using this code in my program I am getting the following errors

these are the errors
doc.cxx:35: no type named `_Ios_Fmtflags' in `class std::ios_base'
doc.cxx: In function `vendor_map_ttbstring_t* init_vendor_table(char*)':
doc.cxx:98: no matching function for call to `std::strstream::setf(const
std::_Ios_Openmode&)'
/usr/include/c++/3.2.3/bits/ios_base.h:345: candidates are: std::_Ios_Fmtflags
std::ios_base::setf(std::_Ios_Fmtflags)
/usr/include/c++/3.2.3/bits/ios_base.h:353: std::_Ios_Fmtflags
std::ios_base::setf(std::_Ios_Fmtflags, std::_Ios_Fmtflags)
doc.cxx:102: no matching function for call to `std::basic_ifstream<char,
std::char_traits<char> >::getline(std::strstreambuf&, char)'
/usr/include/c++/3.2.3/bits/istream.tcc:664: candidates are:
std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
_Traits>::getline(_CharT*, long int, _CharT) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/3.2.3/istream:176: std::basic_istream<_CharT,
_Traits>& std::basic_istream<_CharT, _Traits>::getline(_CharT*, long int)
[with _CharT = char, _Traits = std::char_traits<char>]

this is the code

void get_name_token ( strstream &line, ostrstream & output )
{ //chaitan s->line
// Set line stream for input operations.

//_Ios_Fmtflags f;
ios_base::_Ios_Fmtflags::line.setf(ios::in);

// "Stop" is the char that immediately follows an extracted token
// part in the input stream. If "Stop" is a tab, newline, or EOF
// character, it indicates the end of a token. I give "Stop" an
// arbitrary initial value that is definitely not a delimiter.

char Stop = 'a';

// Eat leading white space and check "Stop" for end of token.
// Quit loop when "Stop" signals the enąd of a token.

while ( line >> ws , (Stop != '\t' && Stop != '\n' && Stop != EOF ))
{
line.get( *output.rdbuf(), ' ' ); // get next token part.

Stop = (char)line.peek(); // Check next char for end of token

if ( Stop == ' ' )
{
// Might be end of token or just an embedded space.
// get the "Stop" character to advance the streambuf ptr.

line.get( Stop );

// If the next character is a space then its the end of the
// token, so we set Stop to EOF to break the while loop.

if ( line.peek() == ' ' )
{
Stop = EOF;
}
else
{
output << Stop;
}
}
}
output << ends;
}



vendor_map_tb_t init_vendor_table( char* vendor_file_name )
{
ifstream vendor_instream ( vendor_file_name );

if ( vendor_instream )
{
// Allocate the vendor_table;

vendor_map_tb_t vendor_table = new gtb(string_t, vendor_map_t)( &stringless, &stringequals );

// eat initial leading blank lines and whitespaces, then
// check for EOF. Loop until the file is empty.

while ( vendor_instream >> ws, !vendor_instream.eof() )
{
// Declare "line" stream and set it for output operations.

// _Ios_Fmtflags f; //chaitan added declaration

strstream line;
line.setf(ios::out); //chaitan ios->ios_base ios::out

// Get a line from the vendor file stream.

vendor_instream.getline( *line.rdbuf(), '\n' );
line << ends;

if ( line.peek() == EOF || line.peek() == '#' )
{
// The line is blank or a comment, so ignore it and start
// again with the next line.

line.clear ();
vendor_instream >> ws;
}
else
{
int count = 0;
ostrstream names[3];

// Get three tokens from the line.

while ( count < 3 ) get_name_token ( line, names[count++] );

// Ignore the rest of the line. This allows us to extend the
// the number of tokens on a line in some future release without
// breaking a translator that expects three tokens on the line.

line.clear();


suggest me the modifications that should be made in this code

Thank you in advance

regards

srikar
Oct 5 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Fendi Baba | last post by:
Hi everyone, I am new to php. I am using a piece of code which is testing if a certain variable is <=0. and the code is written as follows: $lc_align = 'center'; if ($listing<=0) { $lc_text =...
4
by: NewBie | last post by:
Hello Fellows, Can you let me know how do i convert the below VB.NET piece of code into c#? Dim targetTypes(0) as Type targetTypes(0) = GetType(Order) Thanks :)
18
by: __PPS__ | last post by:
Hello, I'm a university student and I'm preparing for my final today. I'm reading course notes, I found completely strange piece of code. It makes me laugh, I think the teacher needs to prepare...
10
by: Extremest | last post by:
I know there are ways to make this a lot faster. Any newsreader does this in seconds. I don't know how they do it and I am very new to c#. If anyone knows a faster way please let me know. All...
8
by: saurabh.ss | last post by:
Hi I want to measure the time required to execute a piece of code. For example, I want to know the time required to execute a given function. How do I do it within C++? I know I got to use a...
4
by: naknak4 | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will...
3
by: Oliver Marshall | last post by:
Hi chaps, I just need a widget of php if anyone has somethign similar to hand. I need to create a .php file that will take an input (&type=xxx or yyy), run a piece of javascript in the browser...
3
by: stephenrussett | last post by:
ok so i ma trying to tur this data: Post Position Street Side Cross_Street Size Time_Limit Yoke 1 1 Sparks E.S. Lyon & Bay DV 1 Hour 2 Piece (New)...
2
by: gsreenathreddy | last post by:
public class Sample { /** * @param args */ public static void main(String args) { // TODO Auto-generated method stub int i=0; for(int j=0;j<5;j++){ i=i++;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.