Jump to content

  • Log In with Google      Sign In   
  • Create Account


Oberon_Command

Member Since 07 May 2003
Offline Last Active Jul 08 2014 10:22 PM
-----

Topics I've Started

[C++] Casting issue with GCC/MinGW implementation of std::string

05 November 2009 - 10:58 AM

I've been getting an error that puzzles me lately while working with Qt and MinGW's std::string implementation. Apparently, I cannot assign a single char to an std::string.
// This code
std::string str = 'x';

// produces this error:
C:/C++/Boron/src/Parser/lexer.cpp:337: error: invalid conversion from `char' to `const char*'
All information I can find suggests that I should be allowed to do this. All my usual references (particularly Cplusplus.com) have example code that states that this will work. I even went into the MinGW std::basic_string header and poked around for the operator=() implementation, and it exists. Yet I get this casting error, which I thought would only have been raised if std::string::operator=(char) was not defined. edit: I ran the following program from cplusplus.com's std::string through GCC:
// string assigning
#include <iostream>
#include <string>
using namespace std;

int main ()
{
  string str1, str2, str3;
  str1 = "Test string: ";   // c-string
  str2 = 'x';               // single character
  str3 = str1 + str2;       // string

  cout << str3  << endl;
  return 0;
}
Now, this compiles and runs just fine, but if I add the following lines to the end of the program, I get that same casting error that I got before:
string str4 = 'y';
cout << str4 << endl;
I haven't worked in C++ much for a little while, and I've never run across this particular issue. What is going on here? Is there something wrong with my MinGW installation, or is this some bug in GCC's implementation of std::string? [Edited by - ApochPiQ on November 5, 2009 7:22:48 PM]

A simple and somewhat clunky Lisp interpreter in C#.

26 October 2009 - 12:53 PM

As I was inspired by "Would you release bad code" thread, I've decided to release the source to this rather unstable and clunky Lisp interpreter I've been sitting on for a little while. I have less use for it than I thought I would (I was going to use it as a scripting engine), and I can't imagine anyone really using it for anything particularly productive, but it was a fun experiment so I'm going to let it loose. You guys can do whatever you like with it, including deride me for my poor coding ability and chew me out on whatever problems you have with it. I might still have a use for it after all, so any suggestions you have would be good ones. I know I'll get flak on documentation at the very least. I don't have much documentation on it, but at least there's a few comments. I always meant to go back and comment it better, but I'm not sure I'll have time now that the fall semester has set in. Some of the less commented stuff is self-explanatory, and some of it is less so. Some of it is an example of what you don't do and why you DO comment. The ConsCell.ToString() method is a perfect example of this. [grin] I'm sure I could have broken my source code up a little better. I'm sure there's still a few bugs lurking down in there. Here it is. edit: And for anyone who wants something to test it with, here is a simple Fahrenheit to Celcius converter program that does run in it:
(define (converter)
  (read "Enter 1 for celcius -> fahrenheit or 2 for fahrenheit -> celcius: " 'choice)
  (cond
    ((= choice 1)
      (progn
        (read "Enter the celcius value: " 'tc)
        (* (/ 9.0 5.0) (+ tc 32))))
    ((= choice 2)
      (progn
  	(read "Enter the fahrenheit value: " 'tf)
	(* (/ 5.0 9.0) (- tf 32))))
    (t (progn (write "Please enter 1 or 2." newline) (converter)))))

When can I call myself a computer scientist?

01 October 2009 - 07:44 AM

The other day in my cognitive systems course, we had to work on a small project in groups. Everyone introduced themselves since none of us really knew each other yet, and of course as is more or less customary we mentioned our majors (COGS is an interdisciplinary field). My major happens to be computer science, so when my turn came to introduce myself I said as much. My exact words however were "I am a computer scientist." Shortly thereafter, I started to wonder if I really have the right to call myself a computer scientist simply because computer science is my major, programming has been my hobby since a young age, and much of what I do is centered around computers and technology. While I know in some sense what a computer scientist is, I am uncertain of where the line between being a computer scientist and not being so is. Therefore, I ask you, GDNet, since you would likely know: at what point and under which conditions may I call myself a "computer scientist?"

All I think about during video games is sex

22 July 2009 - 05:08 AM

It's always while playing FPSs, for some reason. It doesn't matter which game; after some frantic action on-screen, my desire for frantic action OFF-screen increases dramatically. Anyone have any explanation for this? [grin]

Happy Canada day!

01 July 2009 - 07:53 AM

I didn't see a thread on this, so I made one. To all the Canadians on here, happy Canada day! Here's a Canadian flag for you.

PARTNERS