Hi all,
I have written a simple c++ app, as I'm still learning c++. The
thing works flawlessly on VC++6, but just doesn't work on g++. The
transliterate function which causes the problem is supposed to search
for some characters (2 or 1) and replace them with their equivalent
Arabic characters from an array vector<string>. I have been debugging
it on Linux for like 6 hours, and it's really boring that it works on
vc++.
Anyway, tons of thank yous to anyone that can help me with this one:
PS: I noticed:
arabic.size() returns 0??
if I replace it with a number like 6, it just crashes?!
declarations
------------
std::vector<std ::string> arabic; //Array for arabic letters
std::vector<std ::string> english; //Array for english letters
std::vector<std ::string> comments; //Array for comments (ignored)
code
--------
std::string arabize::transl iterate(std::st ring user_ip){
std::cout << "In arabize Transliterator" << std::endl;
std::string CharOrTwo;
std::string text_out; //Holds the Arabic processed text
bool MatchFound=fals e;
if (user_ip.length () < 1) { std::cout << "Write some text first!" <<
std::endl; return "";}
for(int i=0; i < user_ip.length( ) ; ++i){
//Loops over all input characters
if (i < (user_ip.length ()-1)){ //If not at last char
CharOrTwo = user_ip.at(i);
CharOrTwo += user_ip.at(i+1) ; //Take next 2 chars
for(int ctr = 0; ctr < arabic.size(); ctr++) //Problems here
if (CharOrTwo == english[ctr] ){ //Are they in our dictionary?
MatchFound=true ;
text_out += arabic[ctr]; //Put their Arabic equivalent
}
if (MatchFound) {MatchFound=fal se; i++;continue;}//i++ bec we
worked on 2 chars
}
//Next 2 chars didn't match, or we're at last char.
//So, let's match this char we are at
CharOrTwo = user_ip.at(i);
for(int ctr = 0; ctr < arabic.size(); ctr++) //Again is it in
dictionary
if (CharOrTwo == english[ctr] ){
MatchFound=true ;
text_out += arabic[ctr]; //Put their Arabic equivalent
}
if (MatchFound) {MatchFound=fal se;continue;}
}//Done iterating over all input chars
#ifdef _DEBUG
std::cout << "Input:" << user_ip << std::endl <<
"Output:" << text_out << std::endl;
#endif
return text_out;
} 5 1519
Ahmad wrote: I have written a simple c++ app, as I'm still learning c++. The thing works flawlessly on VC++6, but just doesn't work on g++. The transliterate function which causes the problem is supposed to search for some characters (2 or 1) and replace them with their equivalent Arabic characters from an array vector<string>. I have been debugging it on Linux for like 6 hours, and it's really boring that it works on vc++.
Please follow the guidelines from the faq:
[5.8] How do I post a question about code that doesn't work correctly? http://www.parashift.com/c++-faq-lit...t.html#faq-5.8
OK, sorry if I was not very clear. Anyway, after playing with gdb, I
think the problem is clearer (though still strange)
CharOrTwo += user_ip.at(i+1) ; //Take next 2 chars
for(int ctr = 0; ctr < arabic.size(); ctr++) //Problems here
if (CharOrTwo == english[ctr] ){ //Are they in our dictionary?
After the for loop, ctr has strange values of 100,000+ though it
should be from 0 to 5??
any help
Aggro <sp**********@y ahoo.com> wrote in message news:<s8******* ********@read3. inet.fi>... Ahmad wrote:
I have written a simple c++ app, as I'm still learning c++. The thing works flawlessly on VC++6, but just doesn't work on g++. The transliterate function which causes the problem is supposed to search for some characters (2 or 1) and replace them with their equivalent Arabic characters from an array vector<string>. I have been debugging it on Linux for like 6 hours, and it's really boring that it works on vc++.
Please follow the guidelines from the faq:
[5.8] How do I post a question about code that doesn't work correctly?
http://www.parashift.com/c++-faq-lit...t.html#faq-5.8
On 6 Mar 2004 07:58:06 -0800, en****@link.net (Ahmad) wrote: OK, sorry if I was not very clear. Anyway, after playing with gdb, I think the problem is clearer (though still strange)
CharOrTwo += user_ip.at(i+1) ; //Take next 2 chars for(int ctr = 0; ctr < arabic.size(); ctr++) //Problems here if (CharOrTwo == english[ctr] ){ //Are they in our dictionary?
After the for loop, ctr has strange values of 100,000+ though it should be from 0 to 5?? any help
You haven't posted all your code, so I can't tell for sure, but I suspect
you may be getting bitten by the "scope of a variable defined in a for
loop" issue.
In VC6, saying something like:
for (int i = 0; i < whatever; ++i)
{
// whatever
}
is the same as saying:
int i;
for (i = 0; i < whatever; ++i)
{ // whatever
}
IOW, i remains in scope after the end of the loop. gcc probably does it
/right/, which is to say, the first version above is "as if" you wrote:
{
int i;
for (i = 0; i < whatever; ++i)
{ // whatever
}
}
So perhaps you've got a version of your loop variable, "ctr", visible at
the scope outside of the for loop? A global perchance? Just grasping at
straws here...
-leor
Leor Zolman
BD Software le**@bdsoft.com www.bdsoft.com -- On-Site Training in C/C++, Java, Perl & Unix
C++ users: Download BD Software's free STL Error Message
Decryptor at www.bdsoft.com/tools/stlfilt.html
"Ahmad" <en****@link.ne t> wrote in message
news:30******** *************** **@posting.goog le.com... OK, sorry if I was not very clear. Anyway, after playing with gdb, I think the problem is clearer (though still strange)
CharOrTwo += user_ip.at(i+1) ; //Take next 2 chars for(int ctr = 0; ctr < arabic.size(); ctr++) //Problems here if (CharOrTwo == english[ctr] ){ //Are they in our dictionary?
After the for loop, ctr has strange values of 100,000+ though it should be from 0 to 5?? any help
I guess you went ahead and ignored the posting guidelines. Please post a
*complete*, *compilable*, example that demonstrates the problem.
have been debugging it on Linux for like 6 hours, and it's really boring that it works on vc++.
This really doesn't mean anything, that it "works on vc++". There is a
whole bunch of invalid code that I can come up that "works on vc++", but
doesn't take away from the fact that the code could exhibit undefined
behavior when compiled with another compiler.
I see nowhere in the code where you call push_back(), resize(), or construct
the vector objects that would appropriately size them.
#include <vector>
int main()
{
std::vector<int > IV;
IV[0] = 10; // Illegal access
std::vector<int > IV2;
IV2.push_back(1 0); //OK
}
IV has no element 0, since no room for element 0 was created, so you have an
illegal memory access.
You are just lucky that it worked in Visual C++ *if* the code you posted is
all you are doing with the vector. Also, how do you know it is a problem
with vector, and not something else you are doing in the program that may
have corrupted memory?
This is why you should post *minimal*, *compilable* code that duplicates the
problem.
Paul
"Ahmad" <en****@link.ne t> wrote in message
news:30******** *************** **@posting.goog le.com... OK, sorry if I was not very clear. Anyway, after playing with gdb, I think the problem is clearer (though still strange)
CharOrTwo += user_ip.at(i+1) ; //Take next 2 chars for(int ctr = 0; ctr < arabic.size(); ctr++) //Problems here if (CharOrTwo == english[ctr] ){ //Are they in our dictionary?
After the for loop, ctr has strange values of 100,000+ though it should be from 0 to 5?? any help
No still not very clear, please follow the guidelines in the FAQ http://www.parashift.com/c++-faq-lit...t.html#faq-5.8
You will get fast accurate help if you follow these guidelines, if you don't
you will get guesses at best.
john This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Florian Liefers |
last post by:
"Hello World\n",
i have the following problem:
One of my headerfiles for a lib is including <vector>.
When i compile the lib, everything is done well.
In my application another file is including <map>.
By linking my application and the lib, following errors occur:
error LNK2005: "public: __thiscall std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char>
|
by: Sims |
last post by:
Hi,
I have a structure as follow
struct sIntStructure
{
int m_nNumber;
//
// A few more variables
//
|
by: Some Clown |
last post by:
Greetings,
I'm trying to figure out how to loop through a vector of strings, searching
each item as I go for either a boolean condition or a "contains" test. So
if my vector is called 'v' I need to test v.0 for a boolean condition, then
test v.1 and put the results in a new string, etc.
I've tried several methods, none of which have worked. I've also been
looking through my shiny "The C++ Programming Language" guide, but that's
not...
|
by: Russ Ford |
last post by:
I'm trying to overload the << operator to output vectors, as follows:
template <class T>
ostream& operator << (ostream& o, const vector<T>& v)
{
o << "< ";
copy (v.begin(), v.end(), ostream_iterator<T>(o, " ");
return o << ">";
}
|
by: Macca |
last post by:
Hi,
I have been using <fstream.h> in stdafx.h,(i'm using MFC) to output to
text files. I have now started to use vectors and when i added
#include <vector>
using namespace std;
to stdafx.h, I found that to compile i had to change <fstream.h> to
<fstream> to get it to compile.
| |
by: kuiyuli |
last post by:
I'm using VC++ .Net to do a simlple program. I tried to use <vector>
<list> in the program, and I simply put the folowing lines
"
#include <list>
#include <vector>
#include <string>
using namespace std;
......
vector <Vector> vectorlist;
|
by: cagenix |
last post by:
I was running through a data structures book and I was curious if anyone could inform me of how to inherit the vector class to do a simple search and erase function. The example states:
vector_plus is a subclass of the vector class.
vector_plus has no new fields.
Define:
void erase_item(const T& item);
Here is an example of my header file:
|
by: Birthe Gebhardt |
last post by:
Dear all,
I could not find the way to handle 'not normal' list objects, for example
using remove_if, find etc.
Example :
class Todo
{
public :
..
int getNumber(){ return num_;}
|
by: Stefan.Wagenbrenner |
last post by:
Good morning,
I'm trying to write a dll using Dev Cpp 4. I'm able to compile the
following code, but the linker throws an error and no dll is produced:
#include <stdio.h>
#include <windows.h>
#include <vector>
// ... more code ...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |