Search Results

Search found 2886 results on 116 pages for 'std'.

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

  • C++: Why does space always terminate a string when read?

    - by Nullw0rm
    Using type std::string to accept a sentence, for practise (I haven't worked with strings in C++ much) I'm checking if a character is a vowel or not. I got this: for(i = 0; i <= analyse.length(); i++) { if(analyse[i] == 'a' || analyse[i] == 'e' [..etc..]) { ...vowels++; } else { ... ...consenents++; } This works fine if the string is all one word, but the second I add a space (IE: aeio aatest) it will only count the first block and count the space as a consenent, and quit reading the sentence (exiting the for loop or something). Does a space count as no character == null? Or some oddity with std::string?, It would be helpful to know why that is happening!

    Read the article

  • Did C++11 address concerns passing std lib objects between dynamic/shared library boundaries? (ie dlls and so)?

    - by Doug T.
    One of my major complaints about C++ is how hard in practice it is to pass std library objects outside of dynamic library (ie dll/so) boundaries. The std library is often header-only. Which is great for doing some awesome optimizations. However, for dll's, they are often built with different compiler settings that may impact the internal structure/code of a std library containers. For example, in MSVC one dll may build with iterator debugging on while another builds with it off. These two dlls may run into issues passing std containers around. If I expose std::string in my interface, I can't guarantee the code the client is using for std::string is an exact match of my library's std::string. This leads to hard to debug problems, headaches, etc. You either rigidly control the compiler settings in your organization to prevent these issues or you use a simpler C interface that won't have these problems. Or specify to your clients the expected compiler settings they should use (which sucks if another library specifies other compiler settings). My question is whether or not C++11 tried to do anything to solve these issues?

    Read the article

  • RapidXML - does not compile ?

    - by milan
    Hi, I am novice to rapidXML but first impresion was not positive, I made simple Visual Studio 6 C++ Hello World Application and added RapidXML hpp files to project and in main.cpp I put: #include "stdafx.h" #include < iostream > #include < string > #include "rapidxml.hpp" using namespace std; using namespace rapidxml; int main ( ) { char x[] = "<Something>Text</Something>\0" ; //<<<< funktioniert, aber mit '*' nicht xml_document<> doc ; doc.parse<0>(x) ; cout << "Name of my first node is: " << doc.first_node()->name() << endl ; xml_node<>* node = doc.first_node("Something") ; cout << "Node 'Something' has value: " << node->value() << endl ; } And it does not compile, any help ? Is RapidXML possible to run with Visual Studio 6 ? Error I am getting are: --------------------Configuration: aaa - Win32 Debug-------------------- Compiling... rapidxml.cpp c:\Parser\rapidxml.cpp(310) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(320) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(320) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(385) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled c:\Parser\rapidxml.cpp(417) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled c:\Parser\rapidxml.cpp(417) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled c:\Parser\rapidxml.cpp(448) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled c:\Parser\rapidxml.cpp(448) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled c:\Parser\rapidxml.cpp(476) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled c:\Parser\rapidxml.cpp(579) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled c:\Parser\rapidxml.cpp(599) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled c:\Parser\rapidxml.cpp(681) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(790) : see reference to class template instantiation 'rapidxml::xml_base<Ch>' being compiled c:\Parser\rapidxml.cpp(700) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(790) : see reference to class template instantiation 'rapidxml::xml_base<Ch>' being compiled c:\Parser\rapidxml.cpp(721) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(790) : see reference to class template instantiation 'rapidxml::xml_base<Ch>' being compiled c:\Parser\rapidxml.cpp(751) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(790) : see reference to class template instantiation 'rapidxml::xml_base<Ch>' being compiled c:\Parser\rapidxml.cpp(786) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(790) : see reference to class template instantiation 'rapidxml::xml_base<Ch>' being compiled c:\Parser\rapidxml.cpp(787) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(790) : see reference to class template instantiation 'rapidxml::xml_base<Ch>' being compiled c:\Parser\rapidxml.cpp(836) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(876) : see reference to class template instantiation 'rapidxml::xml_attribute<Ch>' being compiled c:\Parser\rapidxml.cpp(856) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(876) : see reference to class template instantiation 'rapidxml::xml_attribute<Ch>' being compiled c:\Parser\rapidxml.cpp(936) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(1345) : see reference to class template instantiation 'rapidxml::xml_node<Ch>' being compiled c:\Parser\rapidxml.cpp(958) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(1345) : see reference to class template instantiation 'rapidxml::xml_node<Ch>' being compiled c:\Parser\rapidxml.cpp(981) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(1345) : see reference to class template instantiation 'rapidxml::xml_node<Ch>' being compiled c:\Parser\rapidxml.cpp(1004) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(1345) : see reference to class template instantiation 'rapidxml::xml_node<Ch>' being compiled c:\Parser\rapidxml.cpp(1025) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(1345) : see reference to class template instantiation 'rapidxml::xml_node<Ch>' being compiled c:\Parser\rapidxml.cpp(1045) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(1345) : see reference to class template instantiation 'rapidxml::xml_node<Ch>' being compiled Error executing cl.exe. rapidxml.obj - 25 error(s), 0 warning(s)

    Read the article

  • std::map default value for build-in type

    - by Qifa Zhao
    Recently, I was confused by the std::map operator[] function. In the MSDN library, it says: "If the argument key value is not found, then it is inserted along with the default value of the data type." I tryed to search much more exactly explanation for this issue. For example here: std::map default value In this page, Michael Anderson said that "the default value is constructed by the default constructor(zero parameter constructor)". Now my quest comes to this:"what the default value for the build-in type?". Was it compiler related? Or is there a standard for this issue by the c++ stardard committee? I did a test on visual studio 2008 for the "int" type, and found the "int" type is construted with the value 0.

    Read the article

  • calling std::cout.rdbuf() produces syntax error

    - by Mikepote
    Maybe I missed something, but I cant figure out why Visual Studio 2008 isn't seeing the rdbuf() procedure. Here is my code: 16. #include "DebugBuffer/BufferedStringBuf.h" 17. 18. BufferedStringBuf debug_buffer(256); 19. std::cout.rdbuf(&debug_buffer); The BufferedStringBuf class is from this page: http://www.devmaster.net/forums/showthread.php?t=7037 Which produces the following error: ...src\main.cpp(19) : error C2143: syntax error : missing ';' before '.' All I want to do is redirect std::cout to the Visual Studio Output window using OutputDebugString()..

    Read the article

  • passing string literal to std::map::find(..)

    - by ra170
    I've got a std::map. I'm passing string literal to find method. Obviously, I can pass a string literal such as .find("blah"); However, I wanted to declare it upfront, instead of hardcoding the string, so I have couple of choices now: const std::string mystring = "blah"; const char mystring[] = "blah"; static const char * mystring = "blah"; They all work. (or at least compile). My question is, which one should I use? what's the advantage/distavantage over of the other?

    Read the article

  • How to make negate_unary work with any type?

    - by Chan
    Hi, Following this question: How to negate a predicate function using operator ! in C++? I want to create an operator ! can work with any functor that inherited from unary_function. I tried: template<typename T> inline std::unary_negate<T> operator !( const T& pred ) { return std::not1( pred ); } The compiler complained: Error 5 error C2955: 'std::unary_function' : use of class template requires template argument list c:\program files\microsoft visual studio 10.0\vc\include\xfunctional 223 1 Graphic Error 7 error C2451: conditional expression of type 'std::unary_negate<_Fn1>' is illegal c:\program files\microsoft visual studio 10.0\vc\include\ostream 529 1 Graphic Error 3 error C2146: syntax error : missing ',' before identifier 'argument_type' c:\program files\microsoft visual studio 10.0\vc\include\xfunctional 222 1 Graphic Error 4 error C2065: 'argument_type' : undeclared identifier c:\program files\microsoft visual studio 10.0\vc\include\xfunctional 222 1 Graphic Error 2 error C2039: 'argument_type' : is not a member of 'std::basic_ostream<_Elem,_Traits>::sentry' c:\program files\microsoft visual studio 10.0\vc\include\xfunctional 222 1 Graphic Error 6 error C2039: 'argument_type' : is not a member of 'std::basic_ostream<_Elem,_Traits>::sentry' c:\program files\microsoft visual studio 10.0\vc\include\xfunctional 230 1 Graphic Any idea? Update Follow "templatetypedef" solution, I got new error: Error 3 error C2831: 'operator !' cannot have default parameters c:\visual studio 2010 projects\graphic\graphic\main.cpp 39 1 Graphic Error 2 error C2808: unary 'operator !' has too many formal parameters c:\visual studio 2010 projects\graphic\graphic\main.cpp 39 1 Graphic Error 4 error C2675: unary '!' : 'is_prime' does not define this operator or a conversion to a type acceptable to the predefined operator c:\visual studio 2010 projects\graphic\graphic\main.cpp 52 1 Graphic Update 1 Complete code: #include <iostream> #include <functional> #include <utility> #include <cmath> #include <algorithm> #include <iterator> #include <string> #include <boost/assign.hpp> #include <boost/assign/std/vector.hpp> #include <boost/assign/std/map.hpp> #include <boost/assign/std/set.hpp> #include <boost/assign/std/list.hpp> #include <boost/assign/std/stack.hpp> #include <boost/assign/std/deque.hpp> struct is_prime : std::unary_function<int, bool> { bool operator()( int n ) const { if( n < 2 ) return 0; if( n == 2 || n == 3 ) return 1; if( n % 2 == 0 || n % 3 == 0 ) return 0; int upper_bound = std::sqrt( static_cast<double>( n ) ); for( int pf = 5, step = 2; pf <= upper_bound; ) { if( n % pf == 0 ) return 0; pf += step; step = 6 - step; } return 1; } }; /* template<typename T> inline std::unary_negate<T> operator !( const T& pred, typename T::argument_type* dummy = 0 ) { return std::not1<T>( pred ); } */ inline std::unary_negate<is_prime> operator !( const is_prime& pred ) { return std::not1( pred ); } template<typename T> inline void print_con( const T& con, const std::string& ms = "", const std::string& sep = ", " ) { std::cout << ms << '\n'; std::copy( con.begin(), con.end(), std::ostream_iterator<typename T::value_type>( std::cout, sep.c_str() ) ); std::cout << "\n\n"; } int main() { using namespace boost::assign; std::vector<int> nums; nums += 1, 3, 5, 7, 9; nums.erase( remove_if( nums.begin(), nums.end(), !is_prime() ), nums.end() ); print_con( nums, "After remove all primes" ); } Thanks, Chan Nguyen

    Read the article

  • Unmangling the result of std::type_info::name

    - by terminus
    I'm currently working on some logging code that supposed to - among other things - print information about the calling function. This should be relatively easy, standard C++ has a type_info class. This contains the name of the typeid'd class/function/etc. but it's mangled. It's not very usefull. I.e. typeid(std::vector).name() returns "St6vectorIiSaIiEE". Is there a way to produce something usefull from this? Like 'std::vector' for the above example. If it only works for non-template classes, that's fine too. The sollution should work for gcc, but it would be better if I could port it. It's for logging so it's not so important that it can't be turned of, but it should be helpfull for debugging.

    Read the article

  • Is the "==" operator required to be defined to use std::find

    - by user144182
    Let's say I have: class myClass std::list<myClass> myList where myClass does not define the == operator and only consists of public fields. In both VS2010 and VS2005 the following does not compile: myClass myClassVal = myList.front(); std::find( myList.begin(), myList.end(), myClassVal ) complaining about lack of == operator. I naively assumed it would do a value comparison of the myClass object's public members, but I am almost positive this is not correct. I assume if I define a == operator or perhaps use a functor instead, it will solve the problem. Alternatively, if my list was holding pointers instead of values, the comparison would work. Is this right or should I be doing something else?

    Read the article

  • How can I send an std::vector<std::string> over a UNIX socket?

    - by Mike
    For my application, I need to be able to send an std::vector<std::string> over a UNIX socket(local), and get a copy of the vector on the other end of the socket. What's the easiest way to do this with O(1) messages relative to the size of the vector(i.e. without sending a message for each string in the vector)? Since this is all on the same host, and because I control both ends of the socket, I'm not concerned with machine-specific issues such as endinness or vector/string representation.

    Read the article

  • Returning std::vector by value

    - by deft_code
    It is oft said that in C++11 it is sane to return std::vector by value. In C++03 this was mostly true as RVO should optimize away the copy. But that should scared most developers away. In C++11 will a returned std::vector local variable always be moved? What if that vector is a member of a local variable instead of a local variable itself? Obviously returning a global variable will not be moved. What other cases will it not be moved?

    Read the article

  • sort std::list case sensitive elements

    - by Dave18
    #include <list> #include <string> using std::string; using std::list; int main() { list <string> list_; list_.push_back("C"); list_.push_back("a"); list_.push_back("b"); list_.sort(); } does sort() function sort the elements according to their character codes? I want the result here to be a b C after the sorting is done.

    Read the article

  • Iterator to last element in std::list

    - by Dave18
    #include <list> using std::list; int main() { list <int> n; n.push_back(1); n.push_back(2); n.push_back(3); list <int>::iterator iter = n.begin(); std::advance(iter, n.size() - 1); //iter is set to last element } is there any other way to have an iter to the last element in list?

    Read the article

  • C++0x error : variable 'std::packaged_task<int> pt1' has initializer but incomplete type

    - by Eternal Learner
    Hi All, Below is a simple program in c++0x that makes use of packaged_task and futures. while compiling the program i get error : variable 'std::packaged_task pt1' has initializer but incomplete type the program is below #include #include using namespace std; int printFn() { for(int i = 0; i < 100; i++) { cout << "thread " << i << endl; } return 1; } int main() { packaged_task<int> pt1(&printFn); future<int> fut = pt1.get_future(); thread t(move(pt1)); t.detach(); int value = fut.get(); return 0; }

    Read the article

  • how-to initialize 'const std::vector<T>' like a c array

    - by vscharf
    Is there an elegant way to create and initialize a const std::vector<const T> like const T a[] = { ... } to a fixed (and small) number of values? I need to call a function frequently which expects a vector<T>, but these values will never change in my case. In principle I thought of something like namespace { const std::vector<const T> v(??); } since v won't be used outside of this compilation unit.

    Read the article

  • Equivalent of %02d with std::stringstream?

    - by Andreas Brinck
    I wan't to output an integer to a std::stringstream with the equivalent format of printf's %02d. Is there an easier way to achieve this than: std::stringstream stream; stream.setfill('0'); stream.setw(2); stream << value; Is it possible to stream some sort of format flags to the stringstream, something like (pseudocode): stream << flags("%02d") << value;

    Read the article

  • pinpointing "conditional jump or move depends on uninitialized value(s)" valgrind message

    - by kamziro
    So I've been getting some mysterious uninitialized values message from valgrind and it's been quite the mystery as of where the bad value originated from. Seems that valgrind shows the place where the unitialised value ends up being used, but not the origin of the uninitialised value. ==11366== Conditional jump or move depends on uninitialised value(s) ==11366== at 0x43CAE4F: __printf_fp (in /lib/tls/i686/cmov/libc-2.7.so) ==11366== by 0x43C6563: vfprintf (in /lib/tls/i686/cmov/libc-2.7.so) ==11366== by 0x43EAC03: vsnprintf (in /lib/tls/i686/cmov/libc-2.7.so) ==11366== by 0x42D475B: (within /usr/lib/libstdc++.so.6.0.9) ==11366== by 0x42E2C9B: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_float<double>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, char, double) const (in /usr/lib/libstdc++.so.6.0.9) ==11366== by 0x42E31B4: std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::do_put(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, double) const (in /usr/lib/libstdc++.so.6.0.9) ==11366== by 0x42EE56F: std::ostream& std::ostream::_M_insert<double>(double) (in /usr/lib/libstdc++.so.6.0.9) ==11366== by 0x81109ED: Snake::SnakeBody::syncBodyPos() (ostream:221) ==11366== by 0x810B9F1: Snake::Snake::update() (snake.cpp:257) ==11366== by 0x81113C1: SnakeApp::updateState() (snakeapp.cpp:224) ==11366== by 0x8120351: RoenGL::updateState() (roengl.cpp:1180) ==11366== by 0x81E87D9: Roensachs::update() (rs.cpp:321) As can be seen, it gets quite cryptic.. especially because when it's saying by Class::MethodX, it sometimes points straight to ostream etc. Perhaps this is due to optimization? ==11366== by 0x81109ED: Snake::SnakeBody::syncBodyPos() (ostream:221) Just like that. Is there something I'm missing? What is the best way to catch bad values without having to resort to super-long printf detective work?

    Read the article

  • Disable MSBuild output of "Processing /ORDER options..."

    - by Jippers
    The output file from our project build has gone from 6MB to over 75MB in text. Diff'ing the last good build and the first time it blew up, there's a section in the output file like this in the latest: Processing /ORDER options External code objects not listed in the /ORDER file: ?onCallDisconnected@CallStateConnected@CallImpl@space@@UAEXV?$shared_ptr@VCallImpl@space@@@boost@@V?$shared_ptr@VGenericCall@space@@@5@K@Z ; framework.lib(CallStates.obj) ??_DBoolSetting@space@@QAEXXZ ; framework.lib(SettingValueImpl.obj) ...... continues for ~50MB ??$?0U?$pair@$$CBV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@J@std@@@?$allocator@U_Node@?$_Tree_nod@V?$_Tmap_traits@V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@JU?$less@V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@J@std@@@2@$0A@@std@@@std@@@std@@QAE@ABV?$allocator@U?$pair@$$CBV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@J@std@@@1@@Z ; CallStatistics.obj Finished processing /ORDER options I'm not sure how this got in there, but anyone know how to turn it off?

    Read the article

  • Finding minimum value in a Map

    - by Sunny
    I have a map and I want to find the minimum value (right hand side) in the map. Right now here is how I did it bool compare(std::pair<std::string ,int> i, pair<std::string, int> j) { return i.second < j.second; } //////////////////////////////////////////////////// std::map<std::string, int> mymap; mymap["key1"] = 50; mymap["key2"] = 20; mymap["key3"] = 100; std::pair<char, int> min = *min_element(mymap.begin(), mymap.end(), compare); std::cout << "min " << min.second<< " " << std::endl; This works fine and I'm able to get the minimum value the problem is when I put this code inside my class it doesn't seem to work int MyClass::getMin(std::map<std::string, int> mymap) { std::pair<std::string, int> min = *min_element(mymap.begin(), mymap.end(), (*this).compare); //error probably due to this return min.second; } bool MyClass::compare( std::pair<std::string, int> i, std::pair<std::string, int> j) { return i.second < j.second; } Also is there a better solution not involving to writing the additional compare function

    Read the article

  • Bizarre C++ compiler problem

    - by Yassin
    Hi, I have the following C++ code: typedef istream_iterator<string> isi; // (1) vector<string> lineas(isi(cin), isi()); // (2) //vector<string> lineas; //copy(isi(cin), isi(), back_inserter(lineas)); typedef vector<string>::iterator vci; for (vci it = lineas.begin(); it != lineas.end(); ++it) cout &lt;&lt; *it &lt;&lt; endl; However, I get the error while compiling: test.cpp: In function 'int main(int, char**)': test.cpp:16: error: request for member 'begin' in 'lineas', which is of non-class type 'std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >(main(int, char**)::isi, main(int, char**)::isi (*)())' test.cpp:16: error: request for member 'end' in 'lineas', which is of non-class type 'std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >(main(int, char**)::isi, main(int, char**)::isi (*)())' However, if I replace (1) by (2), it compiles. I'm using g++ 4.4.0 What's wrong?

    Read the article

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