dev c++

J

Jason

Hi, hope this isnt the wrong forum, if it is point me in the right
direction.

I am using the mingw compiler on windows xp and I have just installed dev
c++ in order to take advantage of the ide instead of compiling my programs
in dos. However, when i compiled my files it made an error out of

str.push_back(ch) and str.clear()

The error disappears when i use str += ch; and str = ""; instead. Anybody
know why?

And if there is no way around it what is the syntax for using += with a
string pointer, as i am used to str->push_back, is it now *str += ch;?

thanks for your help
 
T

Thomas Tutone

Jason said:
Hi, hope this isnt the wrong forum, if it is point me in the right
direction.

Assuming that "str" is a std::string,"ch" is a char, and your program is
written in standard C++, this is probably the right forum.
I am using the mingw compiler on windows xp and I have just
installed dev
c++ in order to take advantage of the ide instead of compiling my
programs
in dos.

Thanks for providing info about the system you're using, but you've violated
the cardinal rule of asking questions - post compilable code that recreates
the error.
However, when i compiled my files it made an error out of

str.push_back(ch) and str.clear()

What is str? Is it a std::string? What is ch? Is it a char?
The error disappears when i use str += ch; and str = ""; instead.
Anybody
know why?

My guess is there's an error in your program, but since you haven't given
that to us, it's pretty hard to figure out, don't you think?

Try this:

#include <string>
#include <iostream>

int main()
{
std::string str;
char ch('*');
str.push_back(ch);
str += ch;
std::cout << str << '\t' << str.size() << std::endl;
str.clear();
std::cout << str << '\t' << str.size() << std::endl;
}

If that works on your system but your program doesn't work, then it's pretty
clear your program has an error. What does my program do that your program
doesn't?

Best regards,

Tom
 
S

Samuele Armondi

Jason said:
Hi, hope this isnt the wrong forum, if it is point me in the right
direction.

I am using the mingw compiler on windows xp and I have just installed dev
c++ in order to take advantage of the ide instead of compiling my programs
in dos. However, when i compiled my files it made an error out of

str.push_back(ch) and str.clear()

The error disappears when i use str += ch; and str = ""; instead. Anybody
know why?

And if there is no way around it what is the syntax for using += with a
string pointer, as i am used to str->push_back, is it now *str += ch;?

thanks for your help
I used to use Dev-cpp at college, because all they gave us was the free
Borland "compiler" that crashed more times than windows 95... I had problems
with most of the STL, so I downloaded the SGI version (www.sgi.com I think)
and replaced the files. That seemed to fix all the problems.
HTH,
S. Armondi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,883
Members
47,414
Latest member
djangoframe

Latest Threads

Top