std

Linux CLion can't resolve namespace member

我是研究僧i 提交于 2019-12-23 01:02:29
问题 #include <iostream> #include <stdlib.h> int main() { std::srand( time(0) ); return 0; } Error message This code compiles and run fine. But error messsage doesn't disappear and it annoys me. Maybe someone solved this problem. My system info. Linux desktop 4.6.4-1-ARCH #1 SMP PREEMPT Mon Jul 11 19:12:32 CEST 2016 x86_64 GNU/Linux g++ (GCC) 6.1.1 20160707 P.S. The problem appears with included cstdlib. I think the problem in the IDE. 回答1: Solved using C++ 11 < random > 回答2: See https://youtrack

Linux CLion can't resolve namespace member

冷暖自知 提交于 2019-12-23 01:01:11
问题 #include <iostream> #include <stdlib.h> int main() { std::srand( time(0) ); return 0; } Error message This code compiles and run fine. But error messsage doesn't disappear and it annoys me. Maybe someone solved this problem. My system info. Linux desktop 4.6.4-1-ARCH #1 SMP PREEMPT Mon Jul 11 19:12:32 CEST 2016 x86_64 GNU/Linux g++ (GCC) 6.1.1 20160707 P.S. The problem appears with included cstdlib. I think the problem in the IDE. 回答1: Solved using C++ 11 < random > 回答2: See https://youtrack

Is std::equal_to guaranteed to call operator== by default?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-22 18:34:44
问题 I had always thought that the standard required the non-specialized template for std::equal_to<T> to call T::operator== , but I noticed the description at cppreference.com almost implies it's the other way around; certainly it doesn't mention it as a requirement. I also checked the C++11 draft standard N3337 and couldn't find any guarantees there either. If you create a class with an operator== you'd hope it would get used in all circumstances. I can't honestly think of a way to implement std

C++ substitution of ios::noreplace

∥☆過路亽.° 提交于 2019-12-22 18:24:59
问题 I'm using fstream to open a file for write. I don't want to overwrite an existing file so after some searching, I found ios::noreplace. But when I compile this: #include <fstream> using namespace std; //......Did something else. ofstream fout; fout.open(outputFile,ios::noreplace);//outputFile is a C string I get an error error: ‘noreplace’ is not a member of ‘std::ios’ I'm just wondering is there any std:: subsitution for ios::noreplace? 回答1: Some searching on the internet reveals that you

C++ STL container ::clear ::swap

﹥>﹥吖頭↗ 提交于 2019-12-22 11:28:00
问题 What's the fastest way to "clear" a large STL container? In my application, I need to deal with large size std::map , e.g., 10000 elements. I have tested the following 3 methods to clear a std::map . Create a new container every time I need it. Calling map::clear() method. Calling map::swap() method. It seems that ::swap() gives the best result. Can anyone explain why this is the case, please? Is it safe to say that using map::swap() method is the proper way to "clear" a std::map? Is it the

file sort in c++ by modification time

南笙酒味 提交于 2019-12-22 11:12:40
问题 How to sort a file by modification time in C++? std::sort needs a comparison function. It takes vector as the arguments. I want to sort files based on modification. Is there already a comparison function or API available that I can use to achieve this? 回答1: Yes, you can use std::sort and tell it to use a custom comparison object, like this: #include <algorithm> std::vector<string> vFileNames; FileNameModificationDateComparator myComparatorObject; std::sort (vFileNames.begin(), vFileNames.end(

Passing a private method of the class as the compare operator for std::sort

怎甘沉沦 提交于 2019-12-22 08:44:41
问题 I am writing a code to solve the following problem: Given a set of numbers x[0] , x[1] , ..., x[N-1] , find the permutation that makes them sorted in the ascending order. In the other words, I would like to find a permutation on {0,2,...,N-1} such as i[0] , i[1] , ..., i[N-1] such that x[i[0]] <= x[i[1]] <= ... <= x[i[N-1]] . For this, I have stored the x vector and an index vector i (initially filled with i[j] = j ) as private members of a class. I have also defined a private method as bool

Is there a way to optimize std algorithms?

不问归期 提交于 2019-12-22 06:36:52
问题 Searching any information about std algorithms performance, I've found the Stack Overflow question about performance difference between std::max_element() and self-written function. I've tested the functions from the question with GCC 9.2.0 and found no performance difference, i.e. my_max_element_orig() and my_max_element_changed() (from the accepted answer) show the same performance. So it seems like it was just an optimizer issue in GCC 4.8.2. What I really found for GCC 9.2.0 is the

how to use standard library with C++ modules? (eg: `import std.io`)

对着背影说爱祢 提交于 2019-12-22 06:06:13
问题 The basic example given in How do I use C++ modules in Clang? works for me but doesn't import the standard library (eg via import std.stdio; ); after going over http://clang.llvm.org/docs/Modules.html it wasn't clear how to use the standard library in a C++ module, eg: // foo.cppm: export module foo; // works: #include <stdio.h> // none of these work: import std.stdio; import std.io; import std; export void test_foo(){ printf("hello world\n"); } this gives an error: clang++ -std=c++17

Why the order is not preserved when printing something, first with cerr and then cout?

倾然丶 夕夏残阳落幕 提交于 2019-12-22 05:19:13
问题 I have g++ version 4.8.4 compiler with Xubuntu 14.04. In the midst of my OpenCV code (written in Eclipse CDT), I wrote the following three lines consecutively: /* Some codes here*/ cerr << "No match found. # of false positives: " << falsePositives << endl; cout << "Press a key to continue..." << endl; waitKey(0); and here is the result: Press a key to continue... No match found. # of false positives: 1 /*there is a blank line*/ Why the order of those two lines changed at the execution time?