Daily Archives

Articles indexed Monday May 31 2010

Page 9/98 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • Possible reasons for tellg() failing?

    - by Andreas Bonini
    ifstream::tellg() is returning -13 for a certain file. Basically, I wrote a utility that analyzes some source code; I open all files alphabetically, I start with "Apple.cpp" and it works perfectly.. But when it gets to "Conversion.cpp", always on the same file, after reading one line successfully tellg() returns -13. The code in question is: for (int i = 0; i < files.size(); ++i) { /* For each .cpp and .h file */ TextIFile f(files[i]); while (!f.AtEof()) // When it gets to conversion.cpp (not on the others) // first is always successful, second always fails lines.push_back(f.ReadLine()); The code for AtEof is: bool AtEof() { if (mFile.tellg() < 0) FATAL(format("DEBUG - tellg(): %d") % mFile.tellg()); if (mFile.tellg() >= GetSize()) return true; return false; } After it reads successfully the first line of Conversion.cpp, it always crashes with DEBUG - tellg(): -13. This is the whole TextIFile class (wrote by me, the error may be there): class TextIFile { public: TextIFile(const string& path) : mPath(path), mSize(0) { mFile.open(path.c_str(), std::ios::in); if (!mFile.is_open()) FATAL(format("Cannot open %s: %s") % path.c_str() % strerror(errno)); } string GetPath() const { return mPath; } size_t GetSize() { if (mSize) return mSize; const size_t current_position = mFile.tellg(); mFile.seekg(0, std::ios::end); mSize = mFile.tellg(); mFile.seekg(current_position); return mSize; } bool AtEof() { if (mFile.tellg() < 0) FATAL(format("DEBUG - tellg(): %d") % mFile.tellg()); if (mFile.tellg() >= GetSize()) return true; return false; } string ReadLine() { string ret; getline(mFile, ret); CheckErrors(); return ret; } string ReadWhole() { string ret((std::istreambuf_iterator<char>(mFile)), std::istreambuf_iterator<char>()); CheckErrors(); return ret; } private: void CheckErrors() { if (!mFile.good()) FATAL(format("An error has occured while performing an I/O operation on %s") % mPath); } const string mPath; ifstream mFile; size_t mSize; }; Platform is Visual Studio, 32 bit, Windows. Edit: Works on Linux. Edit: I found the cause: line endings. Both Conversion and Guid and others had \n instead of \r\n. I saved them with \r\n instead and it worked. Still, this is not supposed to happen is it?

    Read the article

  • C++: Explicit DLL Loading: First-chance Exception on non "extern C" functions

    - by Shiftbit
    I am having trouble importing my C++ functions. If I declare them as C functions I can successfully import them. When explicit loading, if any of the functions are missing the extern as C decoration I get a the following exception: First-chance exception at 0x00000000 in cpp.exe: 0xC0000005: Access violation. DLL.h: extern "C" __declspec(dllimport) int addC(int a, int b); __declspec(dllimport) int addCpp(int a, int b); DLL.cpp: #include "DLL.h" int addC(int a, int b) { return a + b; } int addCpp(int a, int b) { return a + b; } main.cpp: #include "..DLL/DLL.h" #include <stdio.h> #include <windows.h> int main() { int a = 2; int b = 1; typedef int (*PFNaddC)(int,int); typedef int (*PFNaddCpp)(int,int); HMODULE hDLL = LoadLibrary(TEXT("../Debug/DLL.dll")); if (hDLL != NULL) { PFNaddC pfnAddC = (PFNaddC)GetProcAddress(hDLL, "addC"); PFNaddCpp pfnAddCpp = (PFNaddCpp)GetProcAddress(hDLL, "addCpp"); printf("a=%d, b=%d\n", a,b); printf("pfnAddC: %d\n", pfnAddC(a,b)); printf("pfnAddCpp: %d\n", pfnAddCpp(a,b)); //EXCEPTION ON THIS LINE } getchar(); return 0; } How can I import c++ functions for dynamic loading? I have found that the following code works with implicit loading by referencing the *.lib, but I would like to learn about dynamic loading. Thank you to all in advance.

    Read the article

  • Why is this c++ string concatenation missing a space?

    - by danutenshu
    I am working with c++ strings, and am a beginner at programming. I am expecting: 99 Red Balloons But I am receiving: 99 RedBalloons Why is that? #include <string> #include <iostream> using namespace std; int main() { string text = "9"; string term( "9 "); string info = "Toys"; string color; char hue[4] = {'R','e','d','\0'}; color = hue; info = "Balloons"; text += (term + color + info); cout << endl << text << endl; return 0; }

    Read the article

  • What emoticons can you put into class names in your language?

    - by Chris Gill
    I've just had a "discussion" with a developer about naming classes in C#. My final throw away line was, "Let's not put any emoticons in our class names." I can't think of a way you could put emoticons in C# class names, but I haven't thought too hard about it. Is this possible? Does any programming language allow it? What would be the best/worst language to be able to perform this in? Update: The Scheme answer bests answers my question. It was a quick idea after a quick discussion so I'm going to accept after a short amount of time and then move on with my life. Thanks for the responses.

    Read the article

  • Scala project does not automatically build in Eclipse

    - by stacker
    I copied the examples folder from scala-2.7.7.final-devel-docs to the src folder of a scala project. But the source files will not compiled unless I change them manually. "Project/Build automatically" is checked. I'm using the Scala Eclipse Plugin 2.7.7-final How can I achieve that this works like in java projects?

    Read the article

  • PHP and Apache environment variables

    - by Simon
    Hello, I want to pass an environment variable in linux to apache on start up. export MYVAR=5 --I define my environment variable on the command line PassEnv MYVAR --set apache to import the variable in apache config file apachectl restart --when I restart apache I don't get an error message. However I have noticed that if I do not create the environment variable in my first step, I get a warning message, so must be working here echo $_SERVER['MYVAR'] --i try to access the environment variable within PHP but it is not defined I've observed that if I try to PassEnv an environment variable that already exits (one that I havn't created myself) it works fine. The SetEnv directive also works fine. I'd really like to pass an environment variable to apache on the fly without writing it in a file. Help much appreciated. I'm using CentOS, PHP5 and Apache2. Thanks.

    Read the article

  • Unable to locate the Bug

    - by tzenes
    I was recently on The Daily WTF when I came across this old post. In it the author mentions that one of the programmers changed this code: int main (int argc, char **argv) { int x; char data_string[15]; ... x = 2; strcpy(data_string,"data data data"); ... } To this code: int main (int argc, char **argv) { int x = 2; char data_string[15] = "data data data"; ... } The author goes on to mention: [the coder] changed every single variable to be initiated on the stack For the life of me I cannot see how this change could be harmful, and I am worried that it is a lapse in my C knowledge. What is the WTF?

    Read the article

  • How can I have a smooth animated move between 2 Google Maps locations?

    - by pelms
    When clicking from one marker to another in Google Maps, the map screen animates the move smoothly if both markers are within them initial map view but jumps if one of the markers is off screen. I'm trying to set up a map which has several locations within the main map area but has one which is 'off screen'. I have a signpost icon to the more distant location within the initial map area which I want to smoothly scroll to the off screen location when clicked (so as to give a better sense of it's relative location). I can't find anything in the Maps API which would let me do this however. I could zoom out, move and then zoom in again but this looks a bit jarring. Am I missing something in the API, or does anyone have any suggestions?

    Read the article

  • Haskell - interpreting a number

    - by Abstract
    I have a number 9877342931235. Using Haskell, I need to show it as: 987-734293-123-5 i've tried interspersing the list but of course that puts '-' between every digit. How would I do it to yield the actual result?

    Read the article

  • Hibernate using OneToOne

    - by Soft
    I have two tables tab1 { col1 (PK), col2, col3 } tab2 { col1, col2(PK), col3 } I am using Hibernate annotation for joining using "OneToOne" I have the below Hibernate class for tab1 class tab1 { @OneToOne @JoinColumn(name = "col2", referencedColumnName = "col1") private tab2 t2; } i was expecting to run the below sql select * from tab1 t1, tab2 t2 where t1.col1 = t2.col2 But it is not working as i expected.Please help

    Read the article

  • Meta key in Terminal.app vs national characters

    - by yacoob
    I'm using Terminal.app, and I'd like to use emacs running inside - either locally, or after sshing to remote server. Problem is, I can't get working Meta modifier. Namely, if I enable 'Use option as meta key', Option key works like proper Meta, but I lose ability to enter Polish diacritics (aelósznzc), that are entered with right Option. If I disable 'Use option as meta key', my Meta is gone, but I can again use Polish characters. In this state they appear only with right Option modifier, so I guess it's Terminal.app's fault that it doesn't make a difference between left and right Option key, when the relevant preference is selected. What are my options then? Is there a good solution for my problem? I can always use ESC as a poor man's Meta replacement, but I don't like that idea.

    Read the article

  • I don't get this C/C++ Joke

    - by Buttercup
    After reading this article on thedailywtf.com, I'm not sure that I really got the joke. It says there that some guy changed the code from int function() { int x; char data_string[15]; ... x = 2; strcpy(data_string,"data data data"); ... } to int function() { int x = 2; char data_string[15] = "data data data"; ... } everywhere in the code and that for some reason did inflate the size of the executable from 1 to 2 CDs (or maybe it didn't do that?). Obviously I'm not familiar enough with C/C++ to get this joke, but what seems strangest is that the 2nd code listing seems "cleaner"—at least from what I've been told in school (that is that initializing variables is a good thing, not a bad one).

    Read the article

  • ASP.NET Ajax control toolkit not shown in VS 2008

    - by lmsasu
    I have downloaded the Ajax control toolkit; I have created a new tab in VS 2008 (SP1) toolbox, added the controls from the AjaxControlToolkit.dll,everything went fine. When I removed the toolbox and tried to perform the same steps as above, it didn't work anymore... That is, in the window shown for the "Choose items", the controls are't anutomatically added to the list, as before. What should I do?

    Read the article

  • TextImageRelation Implementation

    - by BobPelotas
    Hello, Does anyone know any information on implementing the TextImageRelation property on a button? Since it is impossible to paint a custom background without having to also paint the foreground, I need at least an idea of how the algorithm works. I can't find any info on it. Thanks

    Read the article

  • Auto-resize custom horizontal scrollbar/slider?

    I'm working on a site that scrolls horizontally. I know very little about jQuery and prototype and I got this slider script working as the page scrollbar. When the window is resized smaller, the custom horizontal slider/scrollbar won't resize to the viewport's width. I have the page and js files here http://keanetix.co.cc/scrollpage/ Try to resize the browser and you'll notice the custom scrollbar extending to the right. The custom scrollbar wont fit on the viewport, unless you refresh the page when it's been resized. Can somebody help me with this? Thanks. This is the code in the HTML page: <script type="text/javascript" language="javascript"> // <![CDATA[ // horizontal slider control var slider2 = new Control.Slider('handle', 'track', { onSlide: function(v) { scrollHorizontal(v, $('scrollable'), slider2); }, onChange: function(v) { scrollHorizontal(v, $('scrollable'), slider2); } }); // scroll the element horizontally based on its width and the slider maximum value function scrollHorizontal(value, element, slider) { element.scrollLeft = Math.round(value/slider.maximum*(element.scrollWidth-element.offsetWidth)); } // disable horizontal scrolling if text doesn't overflow the div if ($('scrollable').scrollWidth <= $('scrollable').offsetWidth) { slider2.setDisabled(); $('track').hide(); } // ]]> </script>

    Read the article

  • Download Specific Images

    - by thebourneid
    I'm trying to search and download specific images /front and back cover / of a website if found but whatever I do I always download only one of them. What should I change in my code to download both of them if found? while ($title_found =~ /'(http:\/\/images.blu-ray.com\/movies\/covers\/\d+_.*?)'/gis) { $url = getSite($1); if ($title_found =~ /front/) { $filename = 'front.jpg'; } elsif ($title_found =~ /back/) { $filename = 'back.jpg'; } } my $dir = 'somepath'.$filename; open F, ">", $dir; binmode F; print F $url; close F; return 0;

    Read the article

  • Ruby GraphViz Binary Tree Record

    - by Jason M
    I'm using the ruby-graphviz gem and I'm trying to draw binary trees. I'd like to use the record shape so that each node can have a left, middle, and right field and, thus, if there are two edges leaving a node, the left and right edges can be distinguished. I tried specifying the field by concatenating the field name like this: @node1.name + ":left" But that did not work. What is the correct way of specifying the field? require 'rubygems' require 'graphviz' @graph = GraphViz.new( :G, :type => :digraph ) @node1 = @graph.add_node("1", "shape" => "record", "label" => "<left>|<f1> 1|<right>" ) @node2 = @graph.add_node("2", "shape" => "record", "label" => "<left>|<f1> 2|<right>" ) @graph.add_edge(@node1.name + ":left", @node2) # generate a random filename filename = "/tmp/#{(0...8).map{65.+(rand(25)).chr}.join}.png" @graph.output( :png => filename ) exec "open #{filename}"

    Read the article

  • How to implement geo-based data store and computation?

    - by Mickey Shine
    Well, let me explain this briefly: 1.I want to build a website that provides location based services, like http://fireeagle.yahoo.net/ . 2.I guess most of these services have something do with longitude and latitude. 3.Is there any particular database/datastore/data structures fit well for such apps? I mean easy to store longitude, latitude and easy to compute or easy to use. I am new to this and any feedbacks are welcome

    Read the article

  • JQUERY, scrollTo, after scrolling down, the page won't let me scroll up for a second... Y?

    - by nobosh
    I'm using the following JQUERY to attach an even to a link in the header, which essentially scrolls to the bottom of the page: $('#comment-count-btn').click(function(){ $('html,body').scrollTo('#comment-wrapper', 500); }); Problem is, that it scrolls all the way to the bottom of the page (which is correct), but then when I try to scroll up a tad, the scroll bar jumps, as if it's locked for a little bit. Any ideas?

    Read the article

  • Remove binding to FrameworkElementFactory

    - by Damien
    I am currently creating a datatemplate to display data in a listview control in a specific manner and bound to the data. This works fine. But I need to be able to remove the bindings when the screen is closed and control is being disposed. How can I do this? I am thinking of just passing null as the second parameter of SetBinding and not sure if this will fix the issue. Also I have tried BindingOperation.ClearBindings, but I have a FrameworkElementFactory object and not a DependancyObject. Any help would be appricaited. //Create a Element Factory object to save the elements that make //up the DataTemplate cellTemplateFactory = new FrameworkElementFactory(typeof(TextBlock)); //Set the binding to the text property of the textblock element var binding = new Binding(dispColumn.BindingField) { TargetNullValue = string.Empty, Mode = BindingMode.OneTime };

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >