473,378 Members | 1,405 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,378 software developers and data experts.

Case-insentive

I'm trying to make a case-insensitive class. Here is the code.
=================================Code============= ====================

#include<bits/char_traits.h>

struct ci_char_traits : public char_traits<char>
{
static bool eq( char c1, char c2 )
{
return toupper(c1) == toupper(c2);
}

static bool lt( char c1, char c2 )
{
return toupper(c1) < toupper(c2);
}

static int compare( const char *s1, const char *s2, size_t n )
{
/*TODO*/
}

static const char* find( const char* s, int n, char a )
{
while( n-- > 0 && toupper(*s) != toupper(a) )
{
++s;
}

return n >= 0 ? s : 0;
}
};

typedef basic_string<char, ci_char_traits> ci_string;

================================================== ===========

===============================Error============== ============
emitrax@freek ~/programming/C++ $ g++ test_ci_string.cc -o test_ci_string
In file included from test_ci_string.cc:3:
ci_string/ci_string.h:30: error: parse error before `<' token
ci_string/ci_string.h:55: error: parse error before `}' token
ci_string/ci_string.h:57: error: syntax error before `;' token
test_ci_string.cc: In function `int main()':
test_ci_string.cc:7: error: `ci_string' undeclared in namespace `std'
test_ci_string.cc:7: error: parse error before `;' token
emitrax@freek ~/programming/C++ $
================================================== ===========

Can anyone help me?

Thanks
Salvo.
Sep 15 '05 #1
3 1774
salvo wrote:
I'm trying to make a case-insensitive class. Here is the code.
=================================Code============= ====================

#include<bits/char_traits.h>

struct ci_char_traits : public char_traits<char>
{
static bool eq( char c1, char c2 )
{
return toupper(c1) == toupper(c2);
}

static bool lt( char c1, char c2 )
{
return toupper(c1) < toupper(c2);
}

static int compare( const char *s1, const char *s2, size_t n )
{
/*TODO*/
}

static const char* find( const char* s, int n, char a )
{
while( n-- > 0 && toupper(*s) != toupper(a) )
{
++s;
}

return n >= 0 ? s : 0;
}
};

typedef basic_string<char, ci_char_traits> ci_string;

================================================== ===========

===============================Error============== ============
emitrax@freek ~/programming/C++ $ g++ test_ci_string.cc -o test_ci_string
In file included from test_ci_string.cc:3:
ci_string/ci_string.h:30: error: parse error before `<' token
ci_string/ci_string.h:55: error: parse error before `}' token
ci_string/ci_string.h:57: error: syntax error before `;' token
test_ci_string.cc: In function `int main()':
test_ci_string.cc:7: error: `ci_string' undeclared in namespace `std'
test_ci_string.cc:7: error: parse error before `;' token
emitrax@freek ~/programming/C++ $
================================================== ===========

Can anyone help me?

Thanks
Salvo.


You could help us by saying which lines 30, 55 and 57 are.

BTW your use of toupper is incorrect.

toupper(c1)

is incorrect if c1 is negative. You should say

toupper((unsigned char)c1)

john
Sep 15 '05 #2
Some guesses follow.

salvo wrote:
I'm trying to make a case-insensitive class. Here is the code.
=================================Code============= ====================

#include<bits/char_traits.h>
This is a non-standard header, replace with

#include <string>

struct ci_char_traits : public char_traits<char>
struct ci_char_traits : public std::char_traits<char>
{
static bool eq( char c1, char c2 )
{
return toupper(c1) == toupper(c2);
}

[snip]
};

typedef basic_string<char, ci_char_traits> ci_string;


typedef std::basic_string<char, ci_char_traits> ci_string;

john
Sep 15 '05 #3

30--> struct ci_char_traits : public char_traits<char>

50--> typedef basic_string<char, ci_char_traits> ci_string;

Thanks John! I got my code compiled.
Those above were the errors. I had to
put std::char_traits and std::basic_string.

Regards
Salvo
Sep 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

32
by: Elliot Temple | last post by:
Hi I have two questions. Could someone explain to me why Python is case sensitive? I find that annoying. Also, why aren't there multiline comments? Would adding them cause a problem of some...
17
by: Newbie | last post by:
Dear friends, I am having a hard time understanding how to use a SELECT CASE in ASP. I have used it in VB but never in ASP scripting. Scenerio: I have 2 textboxes on a form that I have to...
19
by: Robert Scheer | last post by:
Hi. In VBScript I can use a Select Case statement like that: Select Case X Case 1 to 10 'X is between 1 and 10 Case 11,14,16 'X is 11 or 14 or 16 End Select
1
by: ST | last post by:
Hi, I'm trying to debug someone else's code, and I'm going thru this Select Case statement. I'm having problems with the "OTHER" case...in that when the first line of the case is false, it jumps...
2
by: cs168 | last post by:
Hi I am new in ASP programming so I do use the very basic and simple way to do all my stuff. Now I do really got stuck at how can I loop thru the calculation for all my selection.. My full code is as...
10
by: MLH | last post by:
Suppose the following... Dim A as Date A=#7/24/2005# I wish to compare value of A against 2 other values: 1) 8/1/2005 2) 9/1/2005 Which is better and why... First:
7
by: Lauren Quantrell | last post by:
Is there any speed/resource advantage/disadvantage in using Select Case x Case 1 Case 2 etc. many more cases... End Select VS.
22
by: John | last post by:
Hi Folks, I'm experimenting a little with creating a custom CEdit control so that I can decide on what the user is allowed to type into the control. I started off only allowing floating point...
17
by: Navodit | last post by:
So I have some code like: if (document.Insurance.State.selectedIndex == 1) { ifIll(); } else if (document.Insurance.State.selectedIndex == 2) { elseKan(); }
24
by: clockworx05 | last post by:
Hey guys i have this program that i need to write for class. here are the instructions: Write a function called foo that asks the user for their age. Pass the age value to a function called...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.