Search Results

Search found 36715 results on 1469 pages for 'boost string'.

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

  • C: evaluate part of the string

    - by Halst
    I cant find an expression to evaluate a part of a string. I want to get something like that: if (string[4:8]=='abc') {...} I started writing like this: if (string[4]=='a' && string[5]=='b' && string[6]=='c') {...} but if i need to evaluate a big part of string like if (string[10:40] == another_string) {...} then it gets to write TOO much expressions. Are there any ready-to-use solutions?

    Read the article

  • How to fill a section within c++ string?

    - by stacker
    Having a string of whitespaces: string *str = new string(); str->resize(width,' '); I'd like to fill length chars at a position. In C it would look like memset(&str[pos],'#', length ); How can i achieve this with c++ string, I tried string& assign( const string& str, size_type index, size_type len ); but this seems to truncat the original string. Is there an easy C++ way to do this? Thanks.

    Read the article

  • Erasing and modifying elements in Boost MultiIndex Container

    - by Sarah
    I'm trying to use a Boost MultiIndex container in my simulation. My knowledge of C++ syntax is very weak, and I'm concerned I'm not properly removing an element from the container or deleting it from memory. I also need to modify elements, and I was hoping to confirm the syntax and basic philosophy here too. // main.cpp ... #include <boost/multi_index_container.hpp> #include <boost/multi_index/hashed_index.hpp> #include <boost/multi_index/member.hpp> #include <boost/multi_index/ordered_index.hpp> #include <boost/multi_index/mem_fun.hpp> #include <boost/tokenizer.hpp> #include <boost/shared_ptr.hpp> ... #include "Host.h" // class Host, all members private, using get fxns to access using boost::multi_index_container; using namespace boost::multi_index; typedef multi_index_container< boost::shared_ptr< Host >, indexed_by< hashed_unique< const_mem_fun<Host,int,&Host::getID> > // ordered_non_unique< BOOST_MULTI_INDEX_MEM_FUN(Host,int,&Host::getAge) > > // end indexed_by > HostContainer; typedef HostContainer::nth_index<0>::type HostsByID; int main() { ... HostContainer allHosts; Host * newHostPtr; newHostPtr = new Host( t, DOB, idCtr, 0, currentEvents ); allHosts.insert( boost::shared_ptr<Host>(newHostPtr) ); // allHosts gets filled up int randomHostID = 4; int newAge = 50; modifyHost( randomHostID, allHosts, newAge ); killHost( randomHostID, allHosts ); } void killHost( int id, HostContainer & hmap ){ HostsByID::iterator it = hmap.find( id ); cout << "Found host id " << (*it)->getID() << "Attempting to kill. hmap.size() before is " << hmap.size() << " and "; hmap.erase( it ); // Is this really erasing (freeing from mem) the underlying Host object? cout << hmap.size() << " after." << endl; } void modifyHost( int id, HostContainer & hmap, int newAge ){ HostsByID::iterator it = hmap.find( id ); (*it) -> setAge( newAge ); // Not actually the "modify" function for MultiIndex... } My questions are In the MultiIndex container allHosts of shared_ptrs to Host objects, is calling allHosts.erase( it ) on an iterator to the object's shared_ptr enough to delete the object permanently and free it from memory? It appears to be removing the shared_ptr from the container. The allhosts container currently has one functioning index that relies on the host's ID. If I introduce an ordered second index that calls on a member function (Host::getAge()), where the age changes over the course of the simulation, is the index always going to be updated when I refer to it? What is the difference between using the MultiIndex's modify to modify the age of the underlying object versus the approach I show above? I'm vaguely confused about what is assumed/required to be constant in MultiIndex. Thanks in advance. Update Here's my attempt to get the modify syntax working, based on what I see in a related Boost example. struct update_age { update_age():(){} // have no idea what this really does... elicits error void operator() (boost::shared_ptr<Host> ptr) { ptr->incrementAge(); // incrementAge() is a member function of class Host } }; and then in modifyHost, I'd have hmap.modify(it,update_age). Even if by some miracle this turns out to be right, I'd love some kind of explanation of what's going on.

    Read the article

  • C# String.Replace with a start/index (Added my (slow) implementation)

    - by Chris T
    I'd like an efficient method that would work something like this EDIT: Sorry I didn't put what I'd tried before. I updated the example now. // Method signature, Only replaces first instance or how many are specified in max public int MyReplace(ref string source,string org, string replace, int start, int max) { int ret = 0; int len = replace.Length; int olen = org.Length; for(int i = 0; i < max; i++) { // Find the next instance of the search string int x = source.IndexOf(org, ret + olen); if(x > ret) ret = x; else break; // Insert the replacement source = source.Insert(x, replace); // And remove the original source = source.Remove(x + len, olen); // removes original string } return ret; } string source = "The cat can fly but only if he is the cat in the hat"; int i = MyReplace(ref source,"cat", "giraffe", 8, 1); // Results in the string "The cat can fly but only if he is the giraffe in the hat" // i contains the index of the first letter of "giraffe" in the new string The only reason I'm asking is because my implementation I'd imagine getting slow with 1,000s of replaces.

    Read the article

  • Javascript string replace with calculations

    - by Chris
    Is there a way to resolve mathematical expressions in strings in javascript? For example, suppose I want to produce the string "Tom has 2 apples, Lucy has 3 apples. Together they have 5 apples" but I want to be able to substitute in the variables. I can do this with a string replacement: string = "Tom has X apples, Lucy has Y apples. Together they have Z apples"; string2 = string.replace(/X/, '2').replace(/Y/, '3').replace(/Z/, '5'); However, it would be better if, instead of having a variable Z, I could use X+Y. Now, I could also do a string replace for X+Y and replace it with the correct value, but that would become messy when trying to deal with all the possible in-string calculations I might want to do. I suppose I'm looking for a way to achieve this: string = "Something [X], something [Y]. Something [(X+Y^2)/5X]"; And for the [_] parts to be understood as expressions to be resolved before substituting back into the string. Thanks for your help.

    Read the article

  • How to use boost::transform_iterator to iterate over modifed std::map values?

    - by Frank
    I have an std::map, and I would like to define an iterator that returns modified values. Typically, a std::map<int,double>::iterator iterates over std::pair<int,double>, and I would like the same behavior, just the double value is multiplied by a constant. I tried it with boost::transform_iterator, but it doesn't compile: #include <map> #include <boost/iterator/transform_iterator.hpp> #include <boost/functional.hpp> typedef std::map<int,double> Map; Map m; m[100] = 2.24; typedef boost::binder2nd< std::multiplies<double> > Function; typedef boost::transform_iterator<Function, Map::value_type*> MultiplyIter; MultiplyIter begin = boost::make_transform_iterator(m.begin(), Function(std::multiplies<double>(), 4)); // now want to similarly create an end iterator // and then iterate over the modified map The error is: error: conversion from 'boost ::transform_iterator< boost::binder2nd<multiplies<double> >, gen_map<int, double>::iterator , boost::use_default, boost::use_default >' to non-scalar type 'boost::transform_iterator< boost::binder2nd<multiplies<double> >, pair<const int, double> * , boost::use_default, boost::use_default >' requested What is gen_map and do I really need it? I adapted the transform_iterator tutorial code from here to write this code ...

    Read the article

  • Boost Regex unknown number of var

    - by Katrin Thielmann
    I got a Problem with a regex expression and need help. I have some expressions like these in mein .txt File: 19 = NAND (1, 19) regex expression : http://rubular.com/r/U8rO09bvTO With this regex expression i got seperated matches for the numbers. But now I need a regex expression with a unknown size of numbers in the bracket . For example: 19 = NAND (1, 23, 13, 24) match1: 19 match2: 1 match3: 23 match4: 13 match5: 24 I don't know the number of the numbers. So i need a main expression for min 2 numbers in the bracket till a unknow number. I hope somebody can help me.

    Read the article

  • Exposing a pointer in Boost.Python

    - by Goose Bumper
    I have this very simple C++ class: class Tree { public: Node *head; }; BOOST_PYTHON_MODULE(myModule) { class_<Tree>("Tree") .def_readwrite("head",&Tree::head) ; } I want to access the head variable from Python, but the message I see is: No to_python (by-value) converter found for C++ type: Node* From what I understand, this happens because Python is freaking out because it has no concept of pointers. How can I access the head variable from Python? I understand I should use encapsulation, but I'm currently stuck with needing a non-encapsulation solution.

    Read the article

  • Java String.indexOf and empty Strings

    - by tmeisenh
    I'm curious why the String.indexOf is returning a 0 (instead of -1) when asking for the index of an empty string within a string. The Javadocs only say this method returns the index in this String of the specified string, -1 if the string isn't found. System.out.println("FOO".indexOf("")); // outputs 0 wtf!!! System.out.println("FOO".indexOf("bar")); // outputs -1 as expected System.out.println("FOO".indexOf("F")); // outputs 0 as expected System.out.println("".indexOf("")); // outputs 0 as expected, I think

    Read the article

  • Using string.Format for simple things?

    - by Gerrie Schenck
    In my early .Net programming days, I used string.Format() only for complex string concatenations, for example to compile strings as Problem with customer order 234 of date 2/2/2002 and payment id 55543. But now I use string.Format for almost every string concatenation I have to do, also simple ones such as prefixing a string with something. Console.WriteLine(string.Format("\t\t{0}", myString)); Is there any possible overhead on this? Maybe I should use the regular + operator to do these simple operations? What's your opinion on this?

    Read the article

  • boost::spirit (qi) decision between float and double

    - by ChrisInked
    I have a parser which parses different data types from an input file. I already figured out, that spirit can decide between short and int, for example: value %= (shortIntNode | longIntNode); with shortIntNode %= (qi::short_ >> !qi::double_) [qi::_val = phoenix::bind(&CreateShortIntNode, qi::_1)]; longIntNode %= (qi::int_ >> !qi::double_) [qi::_val = phoenix::bind(&CreateLongIntNode, qi::_1)]; I used this type of rules to detect doubles as well (from the answers here and here). The parser was able to decide between int for numbers 65535 and short for numbers <= 65535. But, for float_ and double_ it does not work as expected. It just rounds these values to parse it into a float value, if there is a rule like this: value %= (floatNode | doubleFloatNode); with floatNode %= (qi::float_) [qi::_val = phoenix::bind(&CreateFloatNode, qi::_1)]; doubleFloatNode %= (qi::double_) [qi::_val = phoenix::bind(&CreateDoubleFloatNode, qi::_1)]; Do you know if there is something like an option or some other trick to decide between float_ and double_ depending on the data type range? Thank you very much!

    Read the article

  • Split String in C# without delimiter (sort of)

    - by Zach
    Hi, I want to split a string in C#.NET that looks like this: string Letters = "hello"; and put each letter (h, e, l, l, o) into an array or ArrayList. I have no idea what to use as the delimiter in String.Split(delimiter). I can do it if the original string has commas (or anything else): string Letters = "H,e,l,l,o"; string[] AllLettersArray = Letters.Split(",".ToCharArray()); But I have no idea what to use in a case with (supposedly) no delimiter. Is there a special character like Environment.Newline? Thanks.

    Read the article

  • Boost Test dynamically or statically linked?

    - by Halt
    We use Boost statically linked with our app but now I wan't to use Boost Test with an external test runner and that requires the tests themselves to link dynamically with Boost.Test through the use of the required BOOST_TEST_DYN_LINK define. Is this going to be a problem or is the way Boost Test links completely unrelated to the way the other Boost libraries are linked? Thx.

    Read the article

  • boost.asio's socket's recieve/send functions are bad?

    - by the_drow
    Data may be read from or written to a connected TCP socket using the receive(), async_receive(), send() or async_send() member functions. However, as these could result in short writes or reads, an application will typically use the following operations instead: read(), async_read(), write() and async_write(). I don't really understand that remark as read(), async_read(), write() and async_write() can also end up in short writes or reads, right? Why are those functions not the same? Should I use them at all? Can someone clarify that remark for me?

    Read the article

  • upgrading boost version

    - by idimba
    I'm using RHEL 5.3, shipped with gcc 4.1.2 and boost 1.33. So, there's no boost::unorded_map, no make_shared() factory function to create boost::shared_ptr and other features available in newer releases of boost. Is there're a newer version of boost compatible with the version of gcc? If yes, how the upgrade is performed?

    Read the article

  • Handle complex options with Boost's program_options

    - by R S
    I have a program that generates graphs using different multi-level models. Each multi-level model consists of a generation of a smaller seed graph (say, 50 nodes) which can be created from several models (for example - for each possible edge, choose to include it with probability p). After the seed graph generation, the graph is expanded into a larger one (say 1000 nodes), using one of another set of models. In each of the two stages, each model require a different number of parameters. I would like to be have program_options parse the different possible parameters, according to the names of the models. For example, say I have two seed graphs models: SA, which has 1 parameters, and SB, which has two. Also for the expansion part, I have two models: A and B, again with 1 and 2 parameters, respectively. I would like to be able do something like: ./graph_generator --seed=SA 0.1 --expansion=A 0.2 ./graph_generator --seed=SB 0.1 3 --expansion=A 0.2 ./graph_generator --seed=SA 0.1 --expansion=B 10 20 ./graph_generator --seed=SB 0.1 3 --expansion=B 10 20 and have the parameters parsed correctly. Is that even possible?

    Read the article

  • Parse string to create a list of element

    - by Nick
    I have a string like this: "\r color=\"red\" name=\"Jon\" \t\n depth=\"8.26\" " And I want to parse this string and create a std::list of this object: class data { std::string name; std::string value; }; Where for example: name = color value = red What is the fastest way? I can use boost. EDIT: This is what i've tried: vector<string> tokens; split(tokens, str, is_any_of(" \t\f\v\n\r")); if(tokens.size() > 1) { list<data> attr; for_each(tokens.begin(), tokens.end(), [&attr](const string& token) { if(token.empty() || !contains(token, "=")) return; vector<string> tokens; split(tokens, token, is_any_of("=")); erase_all(tokens[1], "\""); attr.push_back(data(tokens[0], tokens[1])); } ); } But it does not work if there are spaces inside " ": like color="red 1".

    Read the article

  • Why String.replaceAll() don't work on this String ?

    - by Aloong
    //This source is a line read from a file String src = "23570006,music,**,wu(),1,exam,\"Monday9,10(H2-301)\",1-10,score,"; //This sohuld be from a matcher.group() when Pattern.compile("\".*?\"") String group = "\"Monday9,10(H2-301)\""; src = src.replaceAll("\"", ""); group = group.replaceAll("\"", ""); String replacement = group.replaceAll(",", "#@"); System.out.println(src.contains(group)); src = src.replaceAll(group, replacement); System.out.println(group); System.out.println(replacement); System.out.println(src); I'm trying to replace the "," between \"s so I can ues String.split() latter. But the above just not working , the result is: true Monday9,10(H2-301) Monday9#@10(H2-301) 23570006,music,**,wu(),1,exam,Monday9,10(H2-301),1-10,score, but when I change the src string to String src = "123\"9,10\"123"; String group = "\"9,10\""; It works well true 9,10 9#@10 1239#@10123 What's the matter with the string???

    Read the article

  • Using boost::random as the RNG for std::random_shuffle

    - by Greg Rogers
    I have a program that uses the mt19937 random number generator from boost::random. I need to do a random_shuffle and want the random numbers generated for this to be from this shared state so that they can be deterministic with respect to the mersenne twister's previously generated numbers. I tried something like this: void foo(std::vector<unsigned> &vec, boost::mt19937 &state) { struct bar { boost::mt19937 &_state; unsigned operator()(unsigned i) { boost::uniform_int<> rng(0, i - 1); return rng(_state); } bar(boost::mt19937 &state) : _state(state) {} } rand(state); std::random_shuffle(vec.begin(), vec.end(), rand); } But i get a template error calling random_shuffle with rand. However this works: unsigned bar(unsigned i) { boost::mt19937 no_state; boost::uniform_int<> rng(0, i - 1); return rng(no_state); } void foo(std::vector<unsigned> &vec, boost::mt19937 &state) { std::random_shuffle(vec.begin(), vec.end(), bar); } Probably because it is an actual function call. But obviously this doesn't keep the state from the original mersenne twister. What gives? Is there any way to do what I'm trying to do without global variables?

    Read the article

  • Truncate portions of a string to limit the whole string's length in Ruby

    - by Horace Loeb
    Suppose you want to generate dynamic page titles that look like this: "It was all a dream, I used to read word up magazine" from "Juicy" by The Notorious B.I.G I.e., "LYRICS" from "SONG_NAME" by ARTIST However, your title can only be 69 characters total and this template will sometimes generate titles that are longer. One strategy for solving this problem is to truncate the entire string to 69 characters. However, a better approach is to truncate the less important parts of the string first. I.e., your algorithm might look something like this: Truncate the lyrics until the entire string is <= 69 characters If you still need to truncate, truncate the artist name until the entire string is <= 69 characters If you still need to truncate, truncate the song name until the entire string is <= 69 characters If all else fails, truncate the entire string to 69 characters Ideally the algorithm would also limit the amount each part of the string could be truncated. E.g., step 1 would really be "Truncate the lyrics to a minimum of 10 characters until the entire string is <= 69 characters" Since this is such a common situation, I was wondering if someone has a library or code snippet that can take care of it.

    Read the article

  • getting string.substring(N) not to choke when N > string.length

    - by aape
    I'm writing some code that takes a report from the mainframe and converts it to a spreadsheet. They can't edit the code on the MF to give me a delimited file, so I'm stuck dealing with it as fixed width. It's working okay now, but I need to get it more stable before I release it for testing. My problem is that in any given line of data, say it could have three columns of numbers, each five chars wide at positions 10, 16, and 22. If on this one particular row, there's no data for the last two cols, it won't be padded with spaces; rather, the length of the string will be only 14. So, I can't just blindly have dim s as string = someStream.readline a = s.substring(10, 5) b = s.substring(16, 5) c = s.substring(22, 5) because it'll choke when it substrings past the length of the string. I know I could test the length of the string before processing each row, and I have automated the filling of some of the vsariables using a counter and a loop, and using the counter*theWidthOfTheGivenVariable to jump around, but this project was a dog to start with (come on! turning a report into a spreadsheet?), but there are many different types of rows (it's not just a grid), and the code's getting ugly fast. I'd like this to be clean, clear, and maintainable for the poor sucker that gets this after me. If it matters, here's my code so far (it's really crufty at the moment). You can see some of my/its idiocy in the processSection#data subs So, I'm wondering 1) is there a way baked in to .NET to have string.substring not error when reading past the end of a string without wrapping it in a try...catch? and 2) would it be appropriate in this situation to write a new string class that inherits from string that has a more friendly substring function in it? ETA: Thanks for all the advice and knowledge everyone. I'll go with the extension. Hopefully one of these years, I'll get my chops up enough to pay someone back in kind. :)

    Read the article

  • String.split() method bug in GWT 2.0.3

    - by Domchi
    I'm upgrading a GWT project from GWT 1.7.1 to currently newest version 2.0.3. It seems that new GWT broke String.split(String regex) method - I get the following error on the Javascript side: this$static is undefined This happens in this line of my .nocache.js file: if (maxMatch == 0 && this$static.length > 0) { ...which happens to be a part of String split method equivalent in Javascript. Is there a cure for this, apart from doing string splitting myself?

    Read the article

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