Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c++;右值移动语义,关于流的问题_C++_C++11_Move Semantics - Fatal编程技术网

C++ c++;右值移动语义,关于流的问题

C++ c++;右值移动语义,关于流的问题,c++,c++11,move-semantics,C++,C++11,Move Semantics,关于语义和性能的几个问题: x = 0; While (x < 10) { std::cout << "Some text here to send to cout"; ++x; } x=0; 而(x

关于语义和性能的几个问题:

x = 0;
While (x < 10) {
  std::cout << "Some text here to send to cout";
  ++x;
}
x=0;
而(x<10){

std::cout移动字符串文字并不会真正对您有多大好处:它在任何情况下都会生成指针,并且该指针将按值传递。关于使字符串文字保持静态,我希望它不会有任何区别。

移动字符串文字并不会真正对您有多大好处:它在任何情况下都会生成指针,并且is指针将按值传递。关于使字符串文本为静态,我希望它不会有任何区别。

否和否。
运算符否和否没有任何区别。
运算符没有任何区别。
运算符传递的所有内容都是指针。你为什么希望移动会有所帮助?所有这些都是错误的不管怎样,传入的是一个指针。你为什么希望这个移动会有帮助?非常感谢,这都是因为编译器优化吗?似乎反复生成字符串要比在静态内存中生成字符串慢。@bryansammon与优化无关。没有反复创建字符串-没有std::string objec这里涉及ts,字符串文本已经在静态内存中。哦,好的,我明白了,如果它是一个std::string,这会有什么区别吗?如果您创建
std::string
对象,这将非常低效,但仍然不会有任何区别:
std::string
的输出操作符通过
co获取其参数nst&
。移动语义在按值传递对象时非常有用。非常感谢,这都是因为编译器优化吗?似乎反复创建字符串比在静态内存中创建字符串要慢。@bryansammon与优化无关。没有反复创建字符串-没有std::string对象,字符串文本已经在静态内存中。哦,好的,我明白了,那么如果它是std::string,会有什么区别吗?如果您创建
std::string
对象,效率会很低,但仍然不会有任何区别:
std::string
的输出运算符按
const&
。移动语义在按值传递对象时最有用。
   x = 0;
    While (x < 10) {
      std::cout << std::move("Some text here to send to cout");
      ++x;
    }
x = 0;
While (x < 10) {
  static const char* s = "Some text here to send to cout";
  std::cout << s;
  ++x;
}