Search Results

Search found 1031 results on 42 pages for 'iostream'.

Page 3/42 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Is it possible to create ostream object, which outputs to multiple destinations?

    - by fiktor
    In 0-th approximation I have a class class MyClass{ public: ... std::ostream & getOStream(){return f;} private: ofstream f; ... }; Which is used sometimes in the following way: MyClass myclass; myclass.getOStream()<<some<<information<<printed<<here; But now I want to change the class MyClass, so that information will be printed both to f and to std::out, i.e. I want the above line to be equivalent to myclass.f<<some<<information<<printed<<here; std::cout<<some<<information<<printed<<here; I don't know any good way to do that. Do you? Is there any standard solution (for example in stl or in boost)? P.S. I tried to search on this, but it seems that I don't know good keywords. Words multiple, output, ostream, C++, boost seem to be too general.

    Read the article

  • Modify input stream data on the fly

    - by Frizi
    I would like to implement a std::stream modifier/parser, that is doing data manipulation on the fly. Is it possible to create it in form of stream manipulator? For example, i want to strip all the line comments (from any // to the end of line) out of the stdin and pass it to stdout. string str; istream strippingCin = cin >> stripcomments; while(strippingCin.good()) { strippingCin >> str; cout << str; } There may be also a large file input instead of cin, so i don't want to load full stream data into memory at once. Is it possible without writing my own stream class? Maybe is there another route i should take instead?

    Read the article

  • HTTP server that handles requests through IO devices?

    - by StackedCrooked
    This question can probably only be answered for Unix-like systems that follow the "everything is a file" idiom. Would it be hard to create a web server that mounts local devices for handling http traffic? It would enable a program to read raw http requests from /dev/httpin (for example) and write the responses to /dev/httpout. I think this would be nice because it would allow me to create a web server from any programming language that is capable of handling IO streams. I don't really know where to start on this. Any suggestions on how to setup such a system?

    Read the article

  • Custom stream wrappers, what could they be useful for in web applications?

    - by michael
    I suppose the concept is language agnostic, but I don't know what it's called in other languages. In PHP they're Stream Wrappers. In short, a wrapper class that allows manipulation of a streamable resource (resource that can be read to/written to/seek into, such as a file, a db, an url). For example, in a template engine (a view), upon including a template file such as: include "view.wrapper://path/to/my/template/file.phtml"; my custom wrapper, declared elsewhere and associated with "view.wrapper", would first intercepts the file to replace such things as short tags (<?=) with a more verbose counterpart (<?php echo). This allows developers to use short tags in views, even if the server isn't set to allow it. It can also be applied to the preprocessing of views pseudo syntax such as {@myVar} (e.g. replacing it with $this->myVar). This is only one application of custom stream wrappers, but the feature seems powerful enough to make me think that there are others that could make life a lot simpler for developers. What have you built, or thought about building, custom stream wrappers for? where have you seen some interesting implementations? I'm particularly interested in their applications in web development.

    Read the article

  • numbers aren't right when reading text file, have to tally up number of 5 letter words and 6 or more

    - by user320950
    i want to do this: reads the words in the file one at a time. (Use a string to do this) Counts three things: how many single-character words are in the file, how many short (2 to 5 characters) words are in the file, and how many long (6 or more characters) words are in the file. HELP HERE im not sure on how about reading file into a string. i know i have to something like this but i dont understand the rest. HELP HERE ifstream infile; //char mystring[6]; //char mystring[20]; int main() { infile.open("file.txt"); if(infile.fail()) { cout << " Error " << endl; } int numb_char=0; char letter; while(!infile.eof()) { infile.get(letter); cout << letter; numb_char++; break; } cout << " the number of characters is :" << numb_char << endl; infile.close(); return 0;

    Read the article

  • How does the stream manipulators work?

    - by Narek
    It is well known that the user can define stream manipulators like this: ostream& tab(ostream & output) { return output<< '\t'; } And this can be used in main() like this: cout<<'a'<<tab<<'b'<<'c'<<endl; Please explain me how does this all work? If operator<< assumes as a second parameter a pointer to the function that takes and returns ostream &, then please explain my why it is necessary? What would be wrong if the function does not take and return ostream & but it was void instead of ostream &? Also it is interesting why “dec”, “hex” manipulators take effect until I don’t change between them, but user defined manipulators should be always used in order to take effect for each streaming?

    Read the article

  • Writing an ostream filter?

    - by shoosh
    I'd like to write a simple ostream which wraps an argument ostream and changes the stream in some way before passing it on to the argument stream. The transformation is something simple like changing a letter or erasing a word What would a simple class inheriting from ostream look like? What methods should I override?

    Read the article

  • Is there a different between boost iostream mapped file and boost interprocess mapped file?

    - by Yijinsei
    hey guys, want to create a mapped binary file into memory, however I not sure how to create the file to mapped into the system. I read documentation several times and realize there is 2 mapped file, one in iostream and the other in interprocess. Do you guys have any idea on how to create a mapped file into shared memory. I trying to allow multi thread program to read an array of large double written in a binary file format. Also what is the different between the mapped file in iostream and interprocess?

    Read the article

  • Is there a difference between boost iostream mapped file and boost interprocess mapped file?

    - by Yijinsei
    I want to create a mapped binary file into memory; however I am not sure how to create the file to be mapped into the system. I read the documentation several times and realize there are 2 mapped file implementations, one in iostream and the other in interprocess. Do you guys have any idea on how to create a mapped file into shared memory? I am trying to allow a multi-threaded program to read an array of large double written in a binary file format. Also what is the difference between the mapped file in iostream and interprocess?

    Read the article

  • How to switch iostream from binary to text mode and vice versa?

    - by Mad Fish
    I want to read both formatted text and binary data from the same iostream. How can I do that? Why? Imagine this situation: You have different resources, and resource loaders for them, that take a std::istream as a parameter. And there are a "resource source" that provides these streams. Resources can be both text and binary and I need to handle both cases with resource loaders. Or other situation: Image that you have an archive with resources of mixed types. How can I get a text stream from inside the binary archive stream?

    Read the article

  • include and using namespace in C++

    - by cambr
    for using cout, I need to specify both: #include<iostream> and using namespace std; Where is cout defined? in iostream, correct? So, it is that iostream itself is there in namespace std? What is the meaning of both the statements with respect to using cout? I am confused why we need to include them both.

    Read the article

  • Basic question on c++ header file inclusion ?

    - by siva
    What are the differences between below 3 programs ?. Is <iostream> a header file or C++ standard library ? 1 #include<iostream> using namespace std; int main() { return 0; } 2 #include<iostream> int main() { return 0; } 3 #include<iostream.h> int main() { return 0; } Thanks in advance.

    Read the article

  • Building a project in VS that depends on a static and dynamic library

    - by fg nu
    Noob noobin'. I would appreciate some very careful handholding in setting up an example in Visual Studio 2010 Professional where I am trying to build a project which links: a previously built static library, for which the VS project folder is "C:\libjohnpaul\" a previously built dynamic library, for which the VS project folder is "C:\libgeorgeringo\" These are listed as Recipes 1.11, 1.12 and 1.13 in the C++ Cookbook. The project fails to compile for me with unresolved dependencies (see details below), and I can't figure out why. Project 1: Static Library The following are the header and source files that were compiled in this project. I was able to compile this project fine in VS2010, to the named standard library "libjohnpaul.lib" which lives in the folder ("C:/libjohnpaul/Release/"). // libjohnpaul/john.hpp #ifndef JOHN_HPP_INCLUDED #define JOHN_HPP_INCLUDED void john( ); // Prints "John, " #endif // JOHN_HPP_INCLUDED // libjohnpaul/john.cpp #include <iostream> #include "john.hpp" void john( ) { std::cout << "John, "; } // libjohnpaul/paul.hpp #ifndef PAUL_HPP_INCLUDED #define PAUL_HPP_INCLUDED void paul( ); // Prints " Paul, " #endif // PAUL_HPP_INCLUDED // libjohnpaul/paul.cpp #include <iostream> #include "paul.hpp" void paul( ) { std::cout << "Paul, "; } // libjohnpaul/johnpaul.hpp #ifndef JOHNPAUL_HPP_INCLUDED #define JOHNPAUL_HPP_INCLUDED void johnpaul( ); // Prints "John, Paul, " #endif // JOHNPAUL_HPP_INCLUDED // libjohnpaul/johnpaul.cpp #include "john.hpp" #include "paul.hpp" #include "johnpaul.hpp" void johnpaul( ) { john( ); paul( ); Project 2: Dynamic Library Here are the header and source files for the second project, which also compiled fine with VS2010, and the "libgeorgeringo.dll" file lives in the directory "C:\libgeorgeringo\Debug". // libgeorgeringo/george.hpp #ifndef GEORGE_HPP_INCLUDED #define GEORGE_HPP_INCLUDED void george( ); // Prints "George, " #endif // GEORGE_HPP_INCLUDED // libgeorgeringo/george.cpp #include <iostream> #include "george.hpp" void george( ) { std::cout << "George, "; } // libgeorgeringo/ringo.hpp #ifndef RINGO_HPP_INCLUDED #define RINGO_HPP_INCLUDED void ringo( ); // Prints "and Ringo\n" #endif // RINGO_HPP_INCLUDED // libgeorgeringo/ringo.cpp #include <iostream> #include "ringo.hpp" void ringo( ) { std::cout << "and Ringo\n"; } // libgeorgeringo/georgeringo.hpp #ifndef GEORGERINGO_HPP_INCLUDED #define GEORGERINGO_HPP_INCLUDED // define GEORGERINGO_DLL when building libgerogreringo.dll # if defined(_WIN32) && !defined(__GNUC__) # ifdef GEORGERINGO_DLL # define GEORGERINGO_DECL _ _declspec(dllexport) # else # define GEORGERINGO_DECL _ _declspec(dllimport) # endif # endif // WIN32 #ifndef GEORGERINGO_DECL # define GEORGERINGO_DECL #endif // Prints "George, and Ringo\n" #ifdef __MWERKS__ # pragma export on #endif GEORGERINGO_DECL void georgeringo( ); #ifdef __MWERKS__ # pragma export off #endif #endif // GEORGERINGO_HPP_INCLUDED // libgeorgeringo/ georgeringo.cpp #include "george.hpp" #include "ringo.hpp" #include "georgeringo.hpp" void georgeringo( ) { george( ); ringo( ); } Project 3: Executable that depends on the previous libraries Lastly, I try to link the aforecompiled static and dynamic libraries into one project called "helloBeatlesII" which has the project directory "C:\helloBeatlesII" (note that this directory does not nest the other project directories). The linking process that I did is described below: To the "helloBeatlesII" solution, I added the solutions "libjohnpaul" and "libgeorgeringo"; then I changed the properties of the "helloBeatlesII" project to additionally point to the include directories of the other two projects on which it depends ("C:\libgeorgeringo\libgeorgeringo" & "C:\libjohnpaul\libjohnpaul"); added "libgeorgeringo" and "libjohnpaul" to the project dependencies of the "helloBeatlesII" project and made sure that the "helloBeatlesII" project was built last. Trying to compile this project gives me the following unsuccessful build: 1------ Build started: Project: helloBeatlesII, Configuration: Debug Win32 ------ 1Build started 10/13/2012 5:48:32 PM. 1InitializeBuildStatus: 1 Touching "Debug\helloBeatlesII.unsuccessfulbuild". 1ClCompile: 1 helloBeatles.cpp 1ManifestResourceCompile: 1 All outputs are up-to-date. 1helloBeatles.obj : error LNK2019: unresolved external symbol "void __cdecl georgeringo(void)" (?georgeringo@@YAXXZ) referenced in function _main 1helloBeatles.obj : error LNK2019: unresolved external symbol "void __cdecl johnpaul(void)" (?johnpaul@@YAXXZ) referenced in function _main 1E:\programming\cpp\vs-projects\cpp-cookbook\helloBeatlesII\Debug\helloBeatlesII.exe : fatal error LNK1120: 2 unresolved externals 1 1Build FAILED. 1 1Time Elapsed 00:00:01.34 ========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ========== At this point I decided to call in the cavalry. I am new to VS2010, so in all likelihood I am missing something straightforward.

    Read the article

  • g++ on MacOSX doesn't work with -arch ppc64

    - by Albert
    I am trying to build a Universal binary on MacOSX with g++. However, it doesn't really work. I have tried with this simple dummy code: #include <iostream> using namespace std; int main() { cout << "Hello" << endl; } This works fine: % g++ test.cpp -arch i386 -arch ppc -arch x86_64 -o test % file test test: Mach-O universal binary with 3 architectures test (for architecture i386): Mach-O executable i386 test (for architecture ppc7400): Mach-O executable ppc test (for architecture x86_64): Mach-O 64-bit executable x86_64 However, this does not: % g++ test.cpp -arch i386 -arch ppc -arch x86_64 -arch ppc64 -o test In file included from test.cpp:1: /usr/include/c++/4.2.1/iostream:44:28: error: bits/c++config.h: No such file or directory In file included from /usr/include/c++/4.2.1/ios:43, from /usr/include/c++/4.2.1/ostream:45, from /usr/include/c++/4.2.1/iostream:45, from test.cpp:1: /usr/include/c++/4.2.1/iosfwd:45:29: error: bits/c++locale.h: No such file or directory /usr/include/c++/4.2.1/iosfwd:46:25: error: bits/c++io.h: No such file or directory In file included from /usr/include/c++/4.2.1/bits/ios_base.h:45, from /usr/include/c++/4.2.1/ios:48, from /usr/include/c++/4.2.1/ostream:45, from /usr/include/c++/4.2.1/iostream:45, from test.cpp:1: /usr/include/c++/4.2.1/ext/atomicity.h:39:23: error: bits/gthr.h: No such file or directory /usr/include/c++/4.2.1/ext/atomicity.h:40:30: error: bits/atomic_word.h: No such file or directory ... Any idea why that is? I have installed Xcode 3.2.2 with all SDKs it comes with.

    Read the article

  • No Debug information of an iPhone app

    - by Markus Pilman
    Hi all, I wrote an iPhone app which uses a third party library. I crosscompiled this library successfully and everything works smoothly. But when I want to debug the application, it would make sense to also be able to debug the library. So I compiled also the external library with debuging information (usign the gcc option -ggdb). But when I want to debug it, I get the correct symbol names, but the positions are always wrong/extremly wierd (locale_facets.tcc:2505 or iostream:76). For example a stack trace could look like this: #0 0x000045e8 in zorba::serialization::SerializeBaseClass::SerializeBaseClass () at iostream:76 #1 0x0001d990 in zorba::RCObject::RCObject () at iostream:76 #2 0x00025187 in zorba::xqpStringStore::xqpStringStore () at iostream:76 #3 0x000719e4 in zorba::String::String () at locale_facets.tcc:2505 #4 0x00030513 in iphone::iLabelModule::getURI (this=0x533f710) at /Users/sausalito/eth/izorba/sandbox/ilabel.cpp:19 #5 0x00356766 in zorba::static_context::bind_external_module () at locale_facets.tcc:2505 #6 0x0006139d in zorba::StaticContextImpl::registerModule () at locale_facets.tcc:2505 #7 0x000333e5 in -[ZorbaCaller init] (self=0x53405c0, _cmd=0x95583398) at /Users/sausalito/eth/izorba/sandbox/ZorbaCaller.mm:61 #8 0x00033180 in +[ZorbaCaller instance] (self=0x11dc2bc, _cmd=0x93679591) at /Users/sausalito/eth/izorba/sandbox/ZorbaCaller.mm:37 #9 0x0003d998 in -[testOne execute:] (self=0x530d560, _cmd=0x9366b126, sender=0x5121da0) at /Users/sausalito/eth/izorba/sandbox/generator/testOne.mm:13 #10 0x01a21405 in -[UIApplication sendAction:to:from:forEvent:] () #11 0x01a84b4e in -[UIControl sendAction:to:forEvent:] () #12 0x01a86d6f in -[UIControl(Internal) _sendActionsForEvents:withEvent:] () #13 0x01a85abb in -[UIControl touchesEnded:withEvent:] () #14 0x01a3addf in -[UIWindow _sendTouchesForEvent:] () #15 0x01a247c8 in -[UIApplication sendEvent:] () #16 0x01a2b061 in _UIApplicationHandleEvent () #17 0x03b6fd59 in PurpleEventCallback () #18 0x034a8b80 in CFRunLoopRunSpecific () #19 0x034a7c48 in CFRunLoopRunInMode () #20 0x03b6e615 in GSEventRunModal () #21 0x03b6e6da in GSEventRun () #22 0x01a2bfaf in UIApplicationMain () #23 0x0002dd7e in main (argc=1, argv=0xbffff044) at /Users/sausalito/eth/izorba/sandbox/main.m:16 Does anybody have an idea, where these wrong locations come from?

    Read the article

  • linker error in simple program: multiple definition of function

    - by BillyJean
    My function test is added to two different .cpp-files and the functions are private to their respective files as shown below test1.cpp #include <iostream> using namespace std; void test() { cout << "test" << endl; } test2.cpp #include <iostream> using namespace std; void test() { cout << "test" << endl; } main.cpp #include <iostream> using namespace std; int main() { return 0; } During linking I get the error multiple definition of test() - but how is that possible, considering that the two files have their own private scope!? I could understand it if I included the function prototype in each .cpp-files' corresponding header, but there is no such thing in this example.

    Read the article

  • Segmentation fault 11 in MacOS X- C++ [migrated]

    - by Marcos Cesar Vargas Magana
    all. I have a "segmentation fault 11" error when I run the following code. The code actually compiles but I get the error at run time. //** Terror.h ** #include <iostream> #include <string> #include <map> using std::map; using std::pair; using std::string; template<typename Tsize> class Terror { public: //Inserts a message in the map. static Tsize insertMessage(const string& message) { mErrorMessages.insert( pair<Tsize, string>(mErrorMessages.size()+1, message) ); return mErrorMessages.size(); } private: static map<Tsize, string> mErrorMessages; } template<typename Tsize> map<Tsize,string> Terror<Tsize>::mErrorMessages; //** error.h ** #include <iostream> #include "Terror.h" typedef unsigned short errorType; typedef Terror<errorType> error; errorType memoryAllocationError=error::insertMessage("ERROR: out of memory."); //** main.cpp ** #include <iostream> #include "error.h" using namespace std; int main() { try { throw error(memoryAllocationError); } catch(error& err) { } } I have kind of debugging the code and the error happens when the message is being inserted in the static map member. An observation is that if I put the line: errorType memoryAllocationError=error::insertMessage("ERROR: out of memory."); inside the "main()" function instead of at global scope, then everything works fine. But I would like to extend the error messages at global scope, not at local scope. The map is defined static so that all instances of "error" share the same error codes and messages. Do you know how can I get this or something similar. Thank you very much.

    Read the article

  • A Question about using jython when run a receving socket in python

    - by abusemind
    Hi, I have not a lot of knowledge of python and network programming. Currently I am trying to implement a simple application which can receive a text message sent by the user, fetch some information from the google search api, and return the results via text message to the user. This application will continue to listening to the users messages and reply immediately. How I get the text short message sent by the user? It's a program named fetion from the mobile supplier in China. The client side fetion, just like a instant communication tool, can send/receive messages to/from other people who are using mobile to receive/send SMS. I am using a open source python program that simulates the fetion program. So basically I can use this python program to communate with others who using cell phone via SMS. My core program is based on java, so I need to take this python program into java environment. I am using jython, and now I am available to send messages to users by some lines of java codes. But the real question is the process of receving from users via SMS. In python code, a new thread is created to continuously listen to the user. It should be OK in Python, but when I run the similar process in Jython, the following exception occurs: Exception in thread Thread:Traceback (most recent call last): File "D:\jython2.5.1\Lib\threading.py", line 178, in _Thread__bootstrap self.run() File "<iostream>", line 1389, in run File "<iostream>", line 1207, in receive File "<iostream>", line 1207, in receive File "<iostream>", line 150, in recv File "D:\jython2.5.1\Lib\select.py", line 223, in native_select pobj.register(fd, POLLIN) File "D:\jython2.5.1\Lib\select.py", line 104, in register raise _map_exception(jlx) error: (20000, 'socket must be in non-blocking mode') The line 150 in the python code is as follows: def recv(self,timeout=False): if self.login_type == "HTTP": time.sleep(10) return self.get_offline_msg() pass else: if timeout: infd,outfd,errfd = select([self.__sock,],[],[],timeout)//<---line 150 here else: infd,outfd,errfd = select([self.__sock,],[],[]) if len(infd) != 0: ret = self.__tcp_recv() num = len(ret) d_print(('num',),locals()) if num == 0: return ret if num == 1: return ret[0] for r in ret: self.queue.put(r) d_print(('r',),locals()) if not self.queue.empty(): return self.queue.get() else: return "TimeOut" Because of I am not very familiar with python, especially the socket part, and also new in Jython use, I really need your help or only advice or explanation. Thank you very much!

    Read the article

  • question about joGL (glTexImage2D)

    - by Nour
    Hi everybody I was trying to load a texture using joGL library but it seems that something is missing when using this method glTexImage2D at : IOStream wdis = new IOStream(fileName); wdis.skipBytes(18); int width = wdis.readIntW(); // dis.skipBytes(2); int height = wdis.readIntW(); // dis.skipBytes(2); wdis.skipBytes(28); byte buf[] = new byte[wdis.available()]; wdis.read(buf); wdis.close(); gl.glBindTexture(GL.GL_TEXTURE_2D, BMPtextures[index]); gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, 3, width, height, 0, GL.GL_BGR, GL.GL_UNSIGNED_BYTE, buf); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); as IOStream is a class that extends DataInputStream it shows a message that glTexImage2D(int,int,int,int,int,int,int,int,byte[]) is not found at javax.media.opengl.GL I couldn't figure the problem her because it's an open source code and it seems to work perfectly with my friends but unfortunately not with me even though we are using the same library and the same JDK version what shall I do ??

    Read the article

  • Where does gcc keep its built-in include directory paths

    - by Charles
    GCC has built in include directories for certain standard headers. I just need to know where this list is. My newly compiled gcc will not compile my little test C++ program because it cannot find standard headers. I think it fails because of some config options I used to make my file system more organized. I set the bindir and libdir, which I think might have screwed up the built-in include paths for some reason. Program (dummy.c): #include <iostream> void main(){} Command: g++ dummy.c Error: dummy.c:1:20: fatal error: iostream: No such file or directory

    Read the article

  • Program crash on deque from queue

    - by SwedishGit
    My first question asked here, so please excuse if I fail to include something... I'm working on a homework project, which basically consists of creating a "Jukebox" (importing/exporting albums from txt files, creating and "playing" a playlist, etc.). I've become stuck on one point: When "playing" the playlist, which consists of a self-made Queue, a copy of it is made from which songs are dequeued and printed out with a time delay. This appears to run fine on the first run through the program, but if the "play" option is chosen again (with the same playlist, created from a different menu option), it crashes before managing to print the first song. It also crashes if creating a new playlist, but then it manages to print some songs (seem to depend on the number of songs in the first/new playlists...) before crashing. With printouts I've been able to track the crashing down to being on the "item = n-data" call in the deque function... but can't get my head around why this would crash. Below is the code I think should be relevant... let me know if there are other parts that would help if I include. Edit: The Debug Error shown on crash is: R6010 abort() has been called The method to play from the playlist: void Jukebox::playList() { if(songList.getNodes() > 0) { Queue tmpList(songList); Song tmpSong; while(tmpList.deque(tmpSong)) { clock_t temp; temp = clock () + 2 * CLOCKS_PER_SEC ; while (clock() < temp) {} } } else cout << "There are no songs in the playlist!" << endl; } Queue: // Queue.h - Projekt-uppgift // Håkan Sjölin 2014-05-31 //----------------------------------------------------------------------------- #ifndef queue_h #define queue_h #include "Song.h" using namespace std; typedef Song Item; class Node; class Queue { private: Node *first; Node *last; int nodes; public: Queue():first(nullptr),last(nullptr),nodes(0){}; ~Queue(); void enque(Item item); bool deque(Item &item); int getNodes() const { return nodes; } void empty(); }; #endif // Queue.cpp - Projekt-uppgift // Håkan Sjölin 2014-05-31 //----------------------------------------------------------------------------- #include "queue.h" using namespace std; class Node { public: Node *next; Item data; Node (Node *n, Item newData) : next(n), data(newData) {} }; //------------------------------------------------------------------------------ // Funktionsdefinitioner för klassen Queue //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // Destruktor //------------------------------------------------------------------------------ Queue::~Queue() { while(first!=0) { Node *tmp = first; first = first->next; delete tmp; } } //------------------------------------------------------------------------------ // Lägg till data sist i kön //------------------------------------------------------------------------------ void Queue::enque(Item item) { Node *pNew = new Node(0,item); if(getNodes() < 1) first = pNew; else last->next = pNew; last = pNew; nodes++; } //------------------------------------------------------------------------------ // Ta bort data först i kön //------------------------------------------------------------------------------ bool Queue::deque(Item &item) { if(getNodes() < 1) return false; //cout << "deque: test2" << endl; Node *n = first; //cout << "deque: test3" << endl; //cout << "item = " << item << endl; //cout << "first = " << first << endl; //cout << "n->data = " << n->data << endl; item = n->data; //cout << "deque: test4" << endl; first = first->next; //delete n; nodes--; if(getNodes() < 1) // Kön BLEV tom last = nullptr; return true; } //------------------------------------------------------------------------------ // Töm kön //------------------------------------------------------------------------------ void Queue::empty() { while (getNodes() > 0) { Item item; deque(item); } } //------------------------------------------------------------------------------ Song: // Song.h - Projekt-uppgift // Håkan Sjölin 2014-05-15 //----------------------------------------------------------------------------- #ifndef song_h #define song_h #include "Time.h" #include <string> #include <iostream> using namespace std; class Song { private: string title; string artist; Time length; public: Song(); Song(string pTitle, string pArtist, Time pLength); // Setfunktioner void setTitle(string pTitle); void setArtist(string pArtist); void setLength(Time pLength); // Getfunktioner string getTitle() const { return title;} string getArtist() const { return artist;} Time getLength() const { return length;} }; ostream &operator<<(ostream &os, const Song &song); istream &operator>>(istream &is, Song &song); #endif // Song.cpp - Projekt-uppgift // Håkan Sjölin 2014-05-15 //----------------------------------------------------------------------------- #include "Song.h" #include "Constants.h" #include <iostream> //------------------------------------------------------------------------------ // Definiering av Songs medlemsfunktioner //------------------------------------------------------------------------------ // Fövald konstruktor //------------------------------------------------------------------------------ Song::Song() { } //------------------------------------------------------------------------------ // Initieringskonstruktor //------------------------------------------------------------------------------ Song::Song(string pTitle, string pArtist, Time pLength) { title = pTitle; artist = pArtist; length = pLength; } //------------------------------------------------------------------------------ // Setfunktioner //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // setTitle // Ange titel //------------------------------------------------------------------------------ void Song::setTitle(string pTitle) { title = pTitle; } //------------------------------------------------------------------------------ // setArtist // Ange artist //------------------------------------------------------------------------------ void Song::setArtist(string pArtist) { artist = pArtist; } //------------------------------------------------------------------------------ // setTitle // Ange titel //------------------------------------------------------------------------------ void Song::setLength(Time pLength) { length = pLength; } //--------------------------------------------------------------------------- // Överlagring av utskriftsoperatorn //--------------------------------------------------------------------------- ostream &operator<<(ostream &os, const Song &song) { os << song.getTitle() << DELIM << song.getArtist() << DELIM << song.getLength(); return os; } //--------------------------------------------------------------------------- // Överlagring av inmatningsoperatorn //--------------------------------------------------------------------------- istream &operator>>(istream &is, Song &song) { string tmpString; Time tmpLength; getline(is, tmpString, DELIM); song.setTitle(tmpString); getline(is, tmpString, DELIM); song.setArtist(tmpString); is >> tmpLength; is.get(); song.setLength(tmpLength); return is; } //--------------------------------------------------------------------------- Album: // Album.h - Projekt-uppgift // Håkan Sjölin 2014-05-17 //----------------------------------------------------------------------------- #ifndef album_h #define album_h #include "Song.h" #include <string> #include <vector> #include <iostream> using namespace std; class Album { private: string name; vector<Song> songs; public: Album(); Album(string pNameTitle, vector<Song> pSongs); // Setfunktioner void setName(string pName); // Getfunktioner string getName() const { return name;} vector<Song> getSongs() const { return songs;} int getNumberOfSongs() const { return songs.size();} Time getTotalTime() const; void addSong(Song pSong); bool operator<(const Album &album) const; }; ostream &operator<<(ostream &os, const Album &album); istream &operator>>(istream &is, Album &album); #endif // Album.cpp - Projekt-uppgift // Håkan Sjölin 2014-05-17 //----------------------------------------------------------------------------- #include "Album.h" #include "Constants.h" #include <iostream> #include <string> //------------------------------------------------------------------------------ // Definiering av Albums medlemsfunktioner //------------------------------------------------------------------------------ // Fövald konstruktor //------------------------------------------------------------------------------ Album::Album() { } //------------------------------------------------------------------------------ // Initieringskonstruktor //------------------------------------------------------------------------------ Album::Album(string pName, vector<Song> pSongs) { name = pName; songs = pSongs; } //------------------------------------------------------------------------------ // Setfunktioner //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // setName // Ange namn //------------------------------------------------------------------------------ void Album::setName(string pName) { name = pName; } //------------------------------------------------------------------------------ // addSong // Lägg till song //------------------------------------------------------------------------------ void Album::addSong(Song pSong) { songs.push_back(pSong); } //------------------------------------------------------------------------------ // getTotalTime // Returnera total speltid //------------------------------------------------------------------------------ Time Album::getTotalTime() const { Time tTime(0,0,0); for(Song s : songs) { tTime = tTime + s.getLength(); } return tTime; } //--------------------------------------------------------------------------- // Mindre än //--------------------------------------------------------------------------- bool Album::operator<(const Album &album) const { return getTotalTime() < album.getTotalTime(); } //--------------------------------------------------------------------------- // Överlagring av utskriftsoperatorn //--------------------------------------------------------------------------- ostream &operator<<(ostream &os, const Album &album) { os << album.getName() << endl; os << album.getNumberOfSongs() << endl; for (size_t i = 0; i < album.getSongs().size(); i++) os << album.getSongs().at(i) << endl; return os; } //--------------------------------------------------------------------------- // Överlagring av inmatningsoperatorn //--------------------------------------------------------------------------- istream &operator>>(istream &is, Album &album) { string tmpString; int tmpNumberOfSongs; Song tmpSong; getline(is, tmpString); album.setName(tmpString); is >> tmpNumberOfSongs; is.get(); for (int i = 0; i < tmpNumberOfSongs; i++) { is >> tmpSong; album.addSong(tmpSong); } return is; } //--------------------------------------------------------------------------- Time: // Time.h - Projekt-uppgift // Håkan Sjölin 2014-05-15 //----------------------------------------------------------------------------- #ifndef time_h #define time_h #include <iostream> using namespace std; class Time { private: int hours; int minutes; int seconds; public: Time(); Time(int pHour, int pMinute, int pSecond); // Setfunktioner void setHour(int pHour); void setMinute(int pMinute); void setSecond(int pSecond); // Getfunktioner int getHour() const { return hours;} int getMinute() const { return minutes;} int getSecond() const { return seconds;} Time operator+(const Time &time) const; bool operator==(const Time &time) const; bool operator<(const Time &time) const; }; ostream &operator<<(ostream &os, const Time &time); istream &operator>>(istream &is, Time &Time); #endif // Time.cpp - Projekt-uppgift // Håkan Sjölin 2014-05-15 //----------------------------------------------------------------------------- #include "Time.h" #include <iostream> //------------------------------------------------------------------------------ // Definiering av Times medlemsfunktioner //------------------------------------------------------------------------------ // Fövald konstruktor //------------------------------------------------------------------------------ Time::Time() { } //------------------------------------------------------------------------------ // Initieringskonstruktor //------------------------------------------------------------------------------ Time::Time(int pHour, int pMinute, int pSecond) { setHour(pHour); setMinute(pMinute); setSecond(pSecond); } //------------------------------------------------------------------------------ // Setfunktioner //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // setHour // Ange timme //------------------------------------------------------------------------------ void Time::setHour(int pHour) { if(pHour>-1) hours = pHour; else hours = 0; } //------------------------------------------------------------------------------ // setMinute // Ange minut //------------------------------------------------------------------------------ void Time::setMinute(int pMinute) { if(pMinute < 60 && pMinute > -1) { minutes = pMinute; } else minutes = 0; } //------------------------------------------------------------------------------ // setSecond // Ange sekund //------------------------------------------------------------------------------ void Time::setSecond(int pSecond) { if(pSecond < 60 && pSecond > -1) { seconds = pSecond; } else seconds = 0; } //--------------------------------------------------------------------------- // Överlagring av utskriftsoperatorn //--------------------------------------------------------------------------- ostream &operator<<(ostream &os, const Time &time) { os << time.getHour()*3600+time.getMinute()*60+time.getSecond(); return os; } //--------------------------------------------------------------------------- // Överlagring av inmatningsoperatorn //--------------------------------------------------------------------------- istream &operator>>(istream &is, Time &time) { int tmp; is >> tmp; time.setSecond(tmp%60); time.setMinute((tmp/60)%60); time.setHour(tmp/3600); return is; } //--------------------------------------------------------------------------- // Likhet //-------------------------------------------------------------------------- bool Time::operator==(const Time &time) const { return hours == time.getHour() && minutes == time.getMinute() && seconds == time.getSecond(); } //--------------------------------------------------------------------------- // Mindre än //--------------------------------------------------------------------------- bool Time::operator<(const Time &time) const { if(hours == time.getHour()) { if(minutes == time.getMinute()) { return seconds < time.getSecond(); } else { return minutes < time.getMinute(); } } else { return hours < time.getHour(); } } //--------------------------------------------------------------------------- // Addition //--------------------------------------------------------------------------- Time Time::operator+(const Time &time) const { return Time(hours+time.getHour() + (minutes+time.getMinute() + (seconds+time.getSecond())/60)/60, (minutes+time.getMinute() + (seconds+time.getSecond())/60)%60, (seconds+time.getSecond())%60); } //--------------------------------------------------------------------------- Thanks in advance for any help! Edit2: Didn't think of including the more detailed crash info (as it didn't show in the crash pop-up, so to say). Anyway, here it is: Output: 'Jukebox.exe' (Win32): Loaded 'C:\Users\Håkan\Documents\Studier - IT\Objektbaserad programmering i C++\Inlämningsuppgifter\Projekt\Jukebox\Debug\Jukebox.exe'. Symbols loaded. 'Jukebox.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file. 'Jukebox.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file. 'Jukebox.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file. 'Jukebox.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp110d.dll'. Symbols loaded. 'Jukebox.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr110d.dll'. Symbols loaded. The thread 0xe50 has exited with code 0 (0x0). Unhandled exception at 0x0083630C in Jukebox.exe: 0xC0000005: Access violation reading location 0x0000003C. Call stack: > Jukebox.exe!Song::getLength() Line 27 C++ Jukebox.exe!operator<<(std::basic_ostream<char,std::char_traits<char> > & os, const Song & song) Line 59 C++ Jukebox.exe!Queue::deque(Song & item) Line 55 C++ Jukebox.exe!Jukebox::playList() Line 493 C++ Jukebox.exe!Jukebox::play() Line 385 C++ Jukebox.exe!Jukebox::run() Line 536 C++ Jukebox.exe!main() Line 547 C++ Jukebox.exe!__tmainCRTStartup() Line 536 C Jukebox.exe!mainCRTStartup() Line 377 C kernel32.dll!754d86e3() Unknown [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll] ntdll.dll!7748bf39() Unknown ntdll.dll!7748bf0c() Unknown

    Read the article

  • Reading Source Code Aloud

    - by Jon Purdy
    After seeing this question, I got to thinking about the various challenges that blind programmers face, and how some of them are applicable even to sighted programmers. Particularly, the problem of reading source code aloud gives me pause. I have been programming for most of my life, and I frequently tutor fellow students in programming, most often in C++ or Java. It is uniquely aggravating to try to verbally convey the essential syntax of a C++ expression. The speaker must give either an idiomatic translation into English, or a full specification of the code in verbal longhand, using explicit yet slow terms such as "opening parenthesis", "bitwise and", et cetera. Neither of these solutions is optimal. On the one hand, an idiomatic translation is only useful to a programmer who can de-translate back into the relevant programming code—which is not usually the case when tutoring a student. In turn, education (or simply getting someone up to speed on a project) is the most common situation in which source is read aloud, and there is a very small margin for error. On the other hand, a literal specification is aggravatingly slow. It takes far far longer to say "pound, include, left angle bracket, iostream, right angle bracket, newline" than it does to simply type #include <iostream>. Indeed, most experienced C++ programmers would read this merely as "include iostream", but again, inexperienced programmers abound and literal specifications are sometimes necessary. So I've had an idea for a potential solution to this problem. In C++, there is a finite set of keywords—63—and operators—54, discounting named operators and treating compound assignment operators and prefix versus postfix auto-increment and decrement as distinct. There are just a few types of literal, a similar number of grouping symbols, and the semicolon. Unless I'm utterly mistaken, that's about it. So would it not then be feasible to simply ascribe a concise, unique pronunciation to each of these distinct concepts (including one for whitespace, where it is required) and go from there? Programming languages are far more regular than natural languages, so the pronunciation could be standardised. Speakers of any language would be able to verbally convey C++ code, and due to the regularity and fixity of the language, speech-to-text software could be optimised to accept C++ speech with a high degree of accuracy. So my question is twofold: first, is my solution feasible; and second, does anyone else have other potential solutions? I intend to take suggestions from here and use them to produce a formal paper with an example implementation of my solution.

    Read the article

  • compiler warning at C++ template base class

    - by eike
    I get a compiler warning, that I don't understand in that context, when I compile the "Child.cpp" from the following code. (Don't wonder: I stripped off my class declarations to the bare minuum, so the content will not make much sense, but you will see the problem quicker). I get the warning with VS2003 and VS2008 on the highest warning level. The code AbstractClass.h : #include <iostream> template<typename T> class AbstractClass { public: virtual void Cancel(); // { std::cout << "Abstract Cancel" << std::endl; }; virtual void Process() = 0; }; //outside definition. if I comment out this and take the inline //definition like above (currently commented out), I don't get //a compiler warning template<typename T> void AbstractClass<T>::Cancel() { std::cout << "Abstract Cancel" << std::endl; } Child.h : #include "AbstractClass.h" class Child : public AbstractClass<int> { public: virtual void Process(); }; Child.cpp : #include "Child.h" #include <iostream> void Child::Process() { std::cout << "Process" << std::endl; } The warning The class "Child" is derived from "AbstractClass". In "AbstractClass" there's the public method "AbstractClass::Cancel()". If I define the method outside of the class body (like in the code you see), I get the compiler warning... AbstractClass.h(7) : warning C4505: 'AbstractClass::Cancel' : unreferenced local function has been removed with [T=int] ...when I compile "Child.cpp". I do not understand this, because this is a public function and the compiler can't know if I later reference this method or not. And, in the end, I reference this method, because I call it in main.cpp and despite this compiler warning, this method works if I compile and link all files and execute the program: //main.cpp #include <iostream> #include "Child.h" int main() { Child child; child.Cancel(); //works, despite the warning } If I do define the Cancel() function as inline (you see it as out commented code in AbstractClass.h), then I don't get the compiler warning. Of course my program works, but I want to understand this warning or is this just a compiler mistake? Furthermore, if do not implement AbsctractClass as a template class (just for a test purpose in this case) I also don't get the compiler warning...?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >