• What Do You Need Help With? V6
    7,544 replies, posted
I think im just going to keep the key on the usb, I never program from the USB directly, just use it for transportation. Anyway Im trying to write a logging class in order to be able to do: [cpp]Log.Info << "Using GLEW " << glewGetString( GLEW_VERSION );[/cpp] And have it print out to both cout and a file [code] [INFO] Using Glew 1.2.3 [/code] What I currently have is: Log Manager [cpp] #ifndef LOG_MANAGER_HPP #define LOG_MANAGER_HPP #include <fstream> #include "Logger.hpp" class LogManager { public: Logger Info; Logger Success; Logger Warning; Logger Error; LogManager() { std::string filename = Util::GetLocalDateTime( "log_%Y-%m-%d_%H-%M-%S.txt" ); mFileStream.open( filename.c_str() ); Info = Logger( Logger::LIGHTCYAN, &mFileStream, "[INFO]"); Success = Logger( Logger::LIGHTGREEN, &mFileStream, "[SUCCESS]"); Warning = Logger( Logger::YELLOW, &mFileStream, "[WARNING]"); Error = Logger( Logger::LIGHTRED, &mFileStream, "[ERROR]"); } ~LogManager() { mFileStream.close(); } protected: std::ofstream mFileStream; }; static LogManager Log; #endif [/cpp] Logger [cpp] #ifndef LOGGER_HPP #define LOGGER_HPP #include <iostream> #include <fstream> #include <iomanip> #include <string> #define TAG_WIDTH 12 class Logger : std::ostream { protected: static int mTagWidth; int mColor; std::ofstream *mFilestr; std::string mType; void ChangeColor(int color) { rlutil::setColor(color); } public: Logger() : std::ostream(std::cout) {} Logger(int color, std::ofstream *ostr, const std::string &type) : std::ostream(std::cout) { mColor = color; mType = type; mFilestr = ostr; } ~Logger() {} template <class T> std::ostream& operator<<(std::ostream& os, const T& t) { ChangeColor(mColor); std::cout << std::left << std::setw(TAG_WIDTH) << mType << t; ChangeColor(WHITE); if(mFilestr->is_open()) { (*mFilestr) << std::left << std::setw(TAG_WIDTH) << mType << t; } return os; } }; #endif [/cpp] But I cant get the operator overload to work: [quote] Error 1 error C2804: binary 'operator <<' has too many parameters 37 1 Framework Error 2 error C2243: 'type cast' : conversion from 'Logger *' to 'std::basic_ostream<_Elem,_Traits> &' exists, but is inaccessible 57 1 Framework [/quote]
[url]http://www.noritake-elec.com/evalkit-sample.php[/url] Its this guy right here, I cannot get this screen to light up and I'm wondering if its simply a programming error. Package came with the screen, a 6 pin cable with connectors, 6 headers, the data sheet, info packets, all that jazz. Here's what I know: I know its getting 5v at somewhere between 250 to 500mA I have the serial baud rate set at 38400, this is what the example code shows plus this is what the datasheet shows is supported. I know the pins are in the right spots and I have the pins on the arduino board activated and set to either input or output, depending on what the data sheet shows. This is the example code provided by the manufacturer, built for arduino boards. The code also came with the complete code libraries for all the GU7000 VFDs from their company, which I have loaded and it compiles without error. [code] #include <GU7000_Interface.h> #include <GU7000_Parallel.h> #include <GU7000_Serial_Async.h> #include <GU7000_Serial_SPI.h> #include <GU7000_Serial_Sync.h> #include <Noritake_VFD_GU7000.h> // **************************************************** // **************************************************** // Uncomment one of the communication interfaces below. // //GU7000_Serial_Async interface(38400,3, 5, 7); // BAUD RATE,SIN,BUSY,RESET //GU7000_Serial_Sync interface(3, 5, 6, 7); // SIN,BUSY,SCK,RESET //GU7000_Serial_SPI interface(3, 5, 6, 7, 8); // SIN,BUSY,SCK,RESET,CS //GU7000_Parallel interface('R', 8,9,10,11, 0,1,2,3,4,5,6,7); // Module Pin#3=RESET; BUSY,RESET,WR,RD,D0-D7 //GU7000_Parallel interface('B', 8,9,10,11, 0,1,2,3,4,5,6,7); // Module Pin#3=BUSY; BUSY,RESET,WR,RD,D0-D7 //GU7000_Parallel interface('N', 8,9,10,11, 0,1,2,3,4,5,6,7); // Module Pin#3=nothing; BUSY,RESET,WR,RD,D0-D7 // // **************************************************** // **************************************************** Noritake_VFD_GU7000 vfd; void setup() { _delay_ms(500); // wait for device to power up vfd.begin(140, 16); // 140x16 module // Enter the 4-digit model class number // E.g. 7040 for GU140X16G-7040A vfd.isModelClass(7000); //vfd.isGeneration('B'); // Uncomment this for B generation vfd.interface(interface); // select which interface to use vfd.GU7000_reset(); // reset module vfd.GU7000_init(); // initialize module // Print Noritake on screen. vfd.print("Noritake"); } void loop() { } [/code] Uncommenting the first serial interface, I have all the pins in place, the board and the VFD are both getting power, I compile the code, send it to the board, board shows it got the code, display stays dark.
[QUOTE=Richy19;42565445][quote]Error 1 error C2804: binary 'operator <<' has too many parameters 37 1 Framework Error 2 error C2243: 'type cast' : conversion from 'Logger *' to 'std::basic_ostream<_Elem,_Traits> &' exists, but is inaccessible 57 1 Framework[/quote][/QUOTE] Which line are these errors at?
[QUOTE=ZeekyHBomb;42566064]Which line are these errors at?[/QUOTE] They were apparently pointing at the operator overload, but in the end I just made it a method that takes in an std::string The only issue I can see it that for things that arent strings I use [cpp]template <class T> inline std::string ToString ( const T &t ) { std::stringstream ss; ss << t; return ss.str(); }[/cpp] Which if im logging somehting each frame, and therefore using the convert to string method it could cause some performance issues. Then again I cant think of any instance where I would log every frame
I spotted the issue: You want to remove the first parameter to the operator<< and return *this. You used the syntax for the operator-overload as a free function (outside of a class definition) inside a class.
I'm trying to create an AI for a checkers game I made using the alpha-beta pruning algorithm, but I keep running into stack overflows. What I understand of the alpha-beta pruning algorithm is that the beta value is the heuristic value of the minimizing player (the opponent), and that the alpha value is the heuristic value of the maximizing player (the AI). Right now I'm only evaluating the heuristic value of the AI's first piece that may make a move, it should evaluate up to 6 steps. For each valid move the piece may make, all of the opponent's possible moving pieces are evaluated, and then it should evaluate the AI's pieces again. Am I doing this right? This is the code, by the way: [code] /// <summary> /// Creates a new DecisionNode /// </summary> /// <param name="ctrl">The Gamecontrol instance.</param> /// <param name="piece">The piece in the next step that should be evaluated.</param> /// <param name="maxPlayer">Determines if the player in the next step is MAX or MIN.</param> /// <param name="depth">Determines the number of steps (plies) that should be evaluated.</param> /// <example>DecisionNode node = new DecisionNode(ctrl, piece, !maxPlayer);</example> public DecisionNode(Gamecontrol ctrl, Piece piece, bool maxPlayer, int depth) { this.ctrl = ctrl; this.maxPlayer = maxPlayer; this.Children = new List<DecisionNode>(); if (depth > 0) { if (maxPlayer) { foreach (Tile t in piece.ValidTiles()) { Piece ghostpiece = new Piece(ctrl, ctrl.GetPlayer(!maxPlayer)); ghostpiece.OnTile = t; DecisionNode node = new DecisionNode(ctrl, ghostpiece, !maxPlayer, maxPlayer ? depth : depth - 1); node.Piece = ghostpiece; Children.Add(node); } } else { foreach (Piece p in ctrl.GetPlayer(false).Pieces) { foreach (Tile t in p.ValidTiles()) { Piece ghost = new Piece(ctrl, ctrl.GetPlayer(false)); ghost.OnTile = t; DecisionNode node = new DecisionNode(ctrl, ghost, !maxPlayer, maxPlayer ? depth : depth - 1); node.Piece = ghost; Children.Add(node); } } } } else if (depth == 0) { MessageBox.Show(this.Piece.OnTile.Location.ToString()); } } //This is in another class that holds a collection of DecisionNodes int Iterate(DecisionNode node, int depth, int alpha, int beta, bool PlayerOnTurn) { if (depth == 0) return node.EvaluateValue(PlayerOnTurn); if (PlayerOnTurn) { foreach (DecisionNode child in node.Children) { alpha = Math.Max(alpha, Iterate(child, depth - 1, alpha, beta, !PlayerOnTurn)); if (beta < alpha) break; } return alpha; } else { foreach (DecisionNode child in node.Children) { beta = Math.Min(beta, Iterate(child, depth - 1, alpha, beta, !PlayerOnTurn)); if (beta < alpha) break; } return beta; } }[/code] GhostPiece is only a temporary piece from which to evaluate the next possible moves.
incredibly basic programming question maybe someone can help me with. I'm doing a online course through coursera on python. I'm trying to get this function to work but I can't for the life of me get it working. I'm just trying to make it so if the value is 0 then the word "rock" is outputted. Anyone familiar with python want to help? On a side note this is the online tool I'm developing the program in. It allows you to save so if anyone wants to put a few comments up there to point in the right direction in setting up functions I would appreciate it [url]http://www.codeskulptor.org/#user20_iSwfXOZvqT_0.py[/url]
[QUOTE=Rofl my Waff;42570007]incredibly basic programming question maybe someone can help me with. I'm doing a online course through coursera on python. I'm trying to get this function to work but I can't for the life of me get it working. I'm just trying to make it so if the value is 0 then the word "rock" is outputted. Anyone familiar with python want to help? On a side note this is the online tool I'm developing the program in. It allows you to save so if anyone wants to put a few comments up there to point in the right direction in setting up functions I would appreciate it [url]http://www.codeskulptor.org/#user20_iSwfXOZvqT_0.py[/url][/QUOTE] How about now? [url]http://www.codeskulptor.org/#user20_iSwfXOZvqT_1.py[/url] I changed it so that a variable "name" is set to the corresponding text, then returned. The print() function, then prints whatever is returned from the function called inside.
Hey guys, a while back I was asking questions about me making a Duck Hunt project for class. I've moved forward a little further than I was before. I've just been doing it on free time now, and whatever in-class time I have. Our teacher is basically telling us to use stuff we learned stuff, and he answers minimal questions, and I am honestly, for the life of me, not able to get the duck shot. Like, when the mouse cursor is clicked on the duck, the duck is shot. I have no idea on how to do it.
[QUOTE=mastersrp;42570151]How about now? [url]http://www.codeskulptor.org/#user20_iSwfXOZvqT_1.py[/url] I changed it so that a variable "name" is set to the corresponding text, then returned. The print() function, then prints whatever is returned from the function called inside.[/QUOTE] that's exactly what I was looking for. I have no idea why I didn't understand what to do. thanks
When using CodeBlocks, after declaring a variable, functions, ect, said names won't appear when I start to type them to autocomplete, but if I restart CodeBlocks it will give me the option to autocomplete. :3 What am I doing wrong :(
[QUOTE=xExigent;42570504]Hey guys, a while back I was asking questions about me making a Duck Hunt project for class. I've moved forward a little further than I was before. I've just been doing it on free time now, and whatever in-class time I have. Our teacher is basically telling us to use stuff we learned stuff, and he answers minimal questions, and I am honestly, for the life of me, not able to get the duck shot. Like, when the mouse cursor is clicked on the duck, the duck is shot. I have no idea on how to do it.[/QUOTE] What language and framework are you using?
[QUOTE=ZeekyHBomb;42566941]I spotted the issue: You want to remove the first parameter to the operator<< and return *this. You used the syntax for the operator-overload as a free function (outside of a class definition) inside a class.[/QUOTE] Thanks, I reimplemented it but with the way it was coded, it outputted [cpp] [INFO] Using OpenGL [INFO] 2.1 [/cpp] I cant really think of any way to get around this. Because when you do [cpp]std::cout << "Hello" << "World" << std::endl;[/cpp] Its treating it as [cpp]std::cout << "Hello"; std::cout << "World"; std::cout << std::endl;[/cpp] Its anoying at the main reason im doing this is to be able to just use << without having to manually convert things to string. BTW, Can you remember when I was re-writing the new and delete opperators to be able to have: [cpp] void *operator new ( const std::size_t size ) throw ( std::bad_alloc ); void *operator new ( const std::size_t size, const MemoryUse::MemoryType type ) throw ( std::bad_alloc ); void *operator new[] ( const std::size_t size ) throw ( std::bad_alloc ); void *operator new[] ( const std::size_t size, const MemoryUse::MemoryType type ) throw ( std::bad_alloc );[/cpp] And pass an enum value to be able to tell what time of memory its using, any idea how I passed that to new? Was it literay: [cpp]MyClass *myClass = new(MemoryType::Something) MyClass();[/cpp]
[QUOTE=Richy19;42573322]Thanks, I reimplemented it but with the way it was coded, it outputted [cpp] [INFO] Using OpenGL [INFO] 2.1 [/cpp] I cant really think of any way to get around this.[/QUOTE] Overload the operator<< with the first parameter as a Logger& instead of ostream&, but still return ostream&. And instead of std::cout use myLoggerInstance. The first text will use your operator<<, the second the STL one (since it gets a ostream&, not a Logger&). [quote] BTW, Can you remember when I was re-writing the new and delete opperators to be able to have: [cpp] void *operator new ( const std::size_t size ) throw ( std::bad_alloc ); void *operator new ( const std::size_t size, const MemoryUse::MemoryType type ) throw ( std::bad_alloc ); void *operator new[] ( const std::size_t size ) throw ( std::bad_alloc ); void *operator new[] ( const std::size_t size, const MemoryUse::MemoryType type ) throw ( std::bad_alloc );[/cpp] And pass an enum value to be able to tell what time of memory its using, any idea how I passed that to new? Was it literay: [cpp]MyClass *myClass = new(MemoryType::Something) MyClass();[/cpp][/QUOTE] Yeah.
[QUOTE=ZeekyHBomb;42573897]Overload the operator<< with the first parameter as a Logger& instead of ostream&, but still return ostream&. And instead of std::cout use myLoggerInstance. The first text will use your operator<<, the second the STL one (since it gets a ostream&, not a Logger&).[/QUOTE] But to do that can I still keep it as a class method overload?
Yes.
[QUOTE=ZeekyHBomb;42574480]Yes.[/QUOTE] When calling the constructor, what should I pass to ostream? currently im passing cout [cpp]Logger::Logger() : std::ostream(std::cout)[/cpp] Also this is my current overload [cpp] template <class T> std::ostream& operator<<(Logger& logger, const T& t) { ChangeColor(mColor); std::cout << std::left << std::setw(TAG_WIDTH) << mType << t; ChangeColor(WHITE); if(mFilestr->is_open()) { (*mFilestr) << std::left << std::setw(TAG_WIDTH) << mType << t; } return *this; } [/cpp] But Im having the same errors: [quote]Error 1 error C2804: binary 'operator <<' has too many parameters 35 1 Framework Error 2 error C2243: 'type cast' : conversion from 'Logger *' to 'std::basic_ostream<_Elem,_Traits> &' exists, but is inaccessible 40 1 Framework Error 3 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'overloaded-function' (or there is no acceptable conversion) 40 1 Framework[/quote] Error 1 points to the logger header, 2 and 3 are when I use it via: [cpp]Log.Info << "Something" << "text" << std::endl;[/cpp] [editline]19th October 2013[/editline] I didnt really understand what you meant by using myLoggerInstance instead of cout
[QUOTE=Richy19;42574546]When calling the constructor, what should I pass to ostream? currently im passing cout [cpp]Logger::Logger() : std::ostream(std::cout)[/cpp][/QUOTE] That works? You're invoking the copy constructor there, which shouldn't be defined. Why are you inheriting from std::ostream? You would need to pass a streambuf*. nullptr should work fine too though. [QUOTE]Also this is my current overload [cpp] template <class T> std::ostream& operator<<(Logger& logger, const T& t) { ChangeColor(mColor); std::cout << std::left << std::setw(TAG_WIDTH) << mType << t; ChangeColor(WHITE); if(mFilestr->is_open()) { (*mFilestr) << std::left << std::setw(TAG_WIDTH) << mType << t; } return *this; } [/cpp] But Im having the same errors: Error 1 points to the logger header, 2 and 3 are when I use it via: [cpp]Log.Info << "Something" << "text" << std::endl;[/cpp] [editline]19th October 2013[/editline] I didnt really understand what you meant by using myLoggerInstance instead of cout[/QUOTE] If Log.Info is of type Logger, then that's why I meant by myLoggerInstance. Remove the explicit Logger& parameter from the operator overload. I thought you were doing it as a free function (but like this there's the implicit this-parameter taking care of it).
[QUOTE=ZeekyHBomb;42574627]That works? You're invoking the copy constructor there, which shouldn't be defined. Why are you inheriting from std::ostream? You would need to pass a streambuf*. nullptr should work fine too though. [/quote] Well it didnt explicitelly break, but it wouldnt compile. I thought I needed to inherit from it to be able to overide the << and have it work as I hoped? [quote] If Log.Info is of type Logger, then that's why I meant by myLoggerInstance. Remove the explicit Logger& parameter from the operator overload. I thought you were doing it as a free function (but like this there's the implicit this-parameter taking care of it).[/QUOTE] I think I have managed to get ridf pretty much every error except, as im just usig it as a template class, its kicking up when I pass in the endl; [editline]19th October 2013[/editline] Oh wait, that error is being caused by: [quote]Error 1 error C2249: 'std::basic_ios<_Elem,_Traits>::operator =' : no accessible path to private member declared in virtual base 'std::basic_ios<_Elem,_Traits>' c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream 604 1 Framework [/quote] Im guessing its because I ass a nullptr to ostream it cant do the things it eeds to do in order to overload properly? [editline]19th October 2013[/editline] Just realized that what were doing wouldnt work, it would output [INFO] to both a file and cout, but then return the ostream which uses the non overloaded which wouldnt output to both file and cout right?
Ah, I didn't look closely enough. I thought you just printed to cout. That approach won't work then. Anyway, first about the inheriting from std::ostream thing, you probably don't need that. To fix the endl-thing, try overloading the operator<< explicitly for std::ostream&(&)(std::ostream&). I'm guessing that a simple typename T does not bind to functions, but that is the type of IO-manipulators: a function returning std::ostream& and taking a std::ostream&. Now, to fix the "[INFO]" thing make the operator<< of Logger private, friend a LoggerPrinter (or LoggerProxy or whatever) struct and implement this as such: [cpp]struct LoggerPrinter final { public: LoggerPrinter(Logger &logger):mLogger(logger) { mLogger << "[INFO] "; } template<typename T> LoggerPrinter operator<<(const T &val) { mLogger << val; } //TODO: overload for io-manip private: Logger &mLogger; };[/cpp] Then overload the operator() or something of Logger to return a LoggerPrinter(*this). You then use Log.Info() << "Something" << "text" << std::endl;, where Log.Info() constructs the LoggerPrinter, which outputs the "[INFO]", and forwards the << stuff to the Logger.
anyone know of any resources on how to make visual studio 2012-like form styles with WPF? google isn't yielding much [editline]19th October 2013[/editline] I know I need WindowStyle none and all, but any resources to help me out are appreciated
How did you guys learn programming (in really any language, doesn't quite matter). I mean, my first experience with programming was LUA with Gmod, as probably a lot of people. After that, I got into BASIC for a class and in between that and the C++ class I'm in now, I experimented with Python and Java. But I find all the material so bland. I love coding, I hate learning about coding. Maybe it's just that my professor makes it so boring or that I have to wake up at 6:30AM for the class. But either way, I'm interested in finding different ways to learn. So far, what I've been doing is trying to find more efficient ways of coding my assignments. We're supposed to be coding at the level that he's teaching, but like, we haven't gotten into Arrays yet and there have been so many assignments where Arrays would have been perfect. So I said fuck it and started coding in Arrays and it hasn't hindered my grades for the class. So anyway, what I'm asking is, did you guys just kinda learn by experimenting with different projects? I find the book and classes quite boring and almost useless to me. In my class, there's practically no hands on learning, it's all looking at PP slides and then trying it out at home. It's horrible.
[QUOTE=Zareox7;42577826]How did you guys learn programming (in really any language, doesn't quite matter). I mean, my first experience with programming was LUA with Gmod, as probably a lot of people. After that, I got into BASIC for a class and in between that and the C++ class I'm in now, I experimented with Python and Java. But I find all the material so bland. I love coding, I hate learning about coding. Maybe it's just that my professor makes it so boring or that I have to wake up at 6:30AM for the class. But either way, I'm interested in finding different ways to learn. So far, what I've been doing is trying to find more efficient ways of coding my assignments. We're supposed to be coding at the level that he's teaching, but like, we haven't gotten into Arrays yet and there have been so many assignments where Arrays would have been perfect. So I said fuck it and started coding in Arrays and it hasn't hindered my grades for the class. So anyway, what I'm asking is, did you guys just kinda learn by experimenting with different projects? I find the book and classes quite boring and almost useless to me. In my class, there's practically no hands on learning, it's all looking at PP slides and then trying it out at home. It's horrible.[/QUOTE] C++ Early Objects. It is by far the best book in my opinion. I did every single checkpoint and the problems at the end of the chapters. It tests your knowledge to the fullest and makes damn well sure you actually learned what you were supposed to learn.
Everyone learns differently. Some people prefer that hands-off learning, others prefer reading books. I in particular just like fiddling with things and researching on google. Find something that suits you and follow it. For example I learned probably 80% of what I know about programming from googling how to make a video game in OpenGL, but don't let that hinder your grades in the class.
In C# how could I make upper case letters into lower case and lower case into upper case in a text?
[QUOTE=bilbasio;42586995]In C# how could I make upper case letters into lower case and lower case into upper case in a text?[/QUOTE] [code] string lowercase = "hello"; string uppercase = lowercase.ToUpper(); [/code] And vice versa.
[QUOTE=benbb;42587372][code] string lowercase = "hello"; string uppercase = lowercase.ToUpper(); [/code] And vice versa.[/QUOTE] What I meant is checking every characters in a text, and every characters that's lowercase needs to be uppercase and vice versa.
[QUOTE=benbb;42587372][code] string lowercase = "hello"; string uppercase = lowercase.ToUpper(); [/code] And vice versa.[/QUOTE] It's worth noting that this function behaves differently depending on the active locale. It should only be used for user input or output and never for data processing. The invariant alternative is .ToUpperInvariant(), similar methods exist for most string manipulation functions. In a similar vein, the index in a string doesn't equal the character offset, just the offset in 16 bit chunks. Small (8-bit) codepoints are extended to two bytes, but everything outside of [URL="http://en.wikipedia.org/wiki/Plane_%28Unicode%29#Basic_Multilingual_Plane"]Basic Multilingual Plane[/URL] is broken into two surrogates and therefore two indices. Combining characters also have to be handled separately if you want to count the length of user input. There's [URL="https://dev.twitter.com/docs/counting-characters"]more information on this in the Twitter documentation[/URL]. [editline]20th October 2013[/editline] [QUOTE=bilbasio;42587466]What I meant is checking every characters in a text, and every characters that's lowercase needs to be uppercase and vice versa.[/QUOTE] You can use char.IsUpper(char) and char.IsLower(char) for that. Don't forget that there are characters that are neither too. As long as there are no surrogates you can just enumerate the characters in an array. With [code]using System.Linq;[/code] you can just call .ToArray() on the string afaik. Don't build the result by concatenating strings with +, instead use either a StringBuilder or the string constructor that takes a char array. (I'm not sure whether the latter can intern the string though.)
[QUOTE=bilbasio;42587466]What I meant is checking every characters in a text, and every characters that's lowercase needs to be uppercase and vice versa.[/QUOTE] [code] string word = "Hello WoRld"; char[] letters = word.ToCharArray(); string newword = ""; foreach(Char letter in letters) { if(Char.IsLower(letter)) { newword = newword + Char.ToUpper(letter); } else { newword = newword + Char.ToLower(letter); } } Console.WriteLine(newword); [/code] Probably can be done better. Tried it on Compileronline.com and it works.
Unless C# has particularly smart string concatenation I would rather output to another char array first and convert that to a string. [editline]21st October 2013[/editline] Actually, can't you modify the array in-place?
Sorry, you need to Log In to post a reply to this thread.