当前位置: 首页>>代码示例>>C++>>正文


C++ std::copy方法代码示例

本文整理汇总了C++中std::copy方法的典型用法代码示例。如果您正苦于以下问题:C++ std::copy方法的具体用法?C++ std::copy怎么用?C++ std::copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std的用法示例。


在下文中一共展示了std::copy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: runtime_error

cheby_coeff::cheby_coeff(const mxArray *c_in){
  if (!is_valid_input(c_in)){
    throw std::runtime_error("cheby_coeff constructor called with invalid input");
  }
  s=mxGetNumberOfElements(c_in);
  m=mxGetNumberOfElements(mxGetCell(c_in,0));
  c.resize(s);
  double *pr_tmp;
  for (int ks=0;ks<s;ks++){
    c[ks].resize(m);
    pr_tmp=mxGetPr(mxGetCell(c_in,ks));
    copy(pr_tmp,pr_tmp+m,c[ks].begin());
  }
}
开发者ID:epfl-lts2,项目名称:gspbox,代码行数:14,代码来源:cheby_op.cpp

示例2: main

int main()
{
    vector<string> p;
    p.push_back("this is an");
    p.push_back("example");
    p.push_back("to");
    p.push_back("illustrate");
    p.push_back("framing");

    ostream_iterator<string> ofile(cout, "\n");
    copy(p.begin(), p.end(), ofile);
    cout << endl;

    vector<string> f = frame(p);
    copy(f.begin(), f.end(), ofile);
    cout << endl;

    vector<string> h = hcat(frame(p), p);
    copy(h.begin(), h.end(), ofile);
    cout << endl;

    return 0;
}
开发者ID:tonylearn09,项目名称:cplusplus-programming-pratice,代码行数:23,代码来源:6-1-main.cpp

示例3: processNode

void AnalyzerManager::processNode(GNode* node, const vector<int>& context) {
	string tag = "AnalyzerManager";
	Logger::d(tag) << "analysis node " << node->getIndex() << endl;
	copy(context.begin(), context.end(),
			ostream_iterator<int>(Logger::d(tag), "->\n"));
	if (mAnalyzersMap.find(node->getTreeCode()) != mAnalyzersMap.end()) {
		//cout<<node->getTreeCode()<<endl;
		vector<BaseAnalyzer*> &analyzerVector =
				mAnalyzersMap[node->getTreeCode()];
		for (vector<BaseAnalyzer*>::iterator itor = analyzerVector.begin();
				itor != analyzerVector.end(); ++itor) {
			(*itor)->analyzeNode(node, context);
		}
	}
}
开发者ID:pkzhiking,项目名称:yy,代码行数:15,代码来源:AnalyzerManager.cpp

示例4: main

int main() {
  vector<int> vec{1, 2, 3, 4, 5, 6, 7, 8, 9};
  vector<int> vec1, vec2;
  list<int> lst;
  auto it1 = back_inserter(vec1);
  auto it2 = front_inserter(lst);
  auto it3 = inserter(vec2, vec2.begin());
  copy(vec.begin(), vec.end(), it1);
  for (auto& x : vec1) {
    cout << x << ' ';
  }
  cout << endl;
  copy(vec.begin(), vec.end(), it2);
  for (auto& x : lst) {
    cout << x << ' ';
  }
  cout << endl;
  copy(vec.begin(), vec.end(), it3);
  for (auto& x : vec2) {
    cout << x << ' ';
  }
  cout << endl;
  return 0;
}
开发者ID:MisLink,项目名称:CppPrimer,代码行数:24,代码来源:ex28.cpp

示例5: compose_name

// The output buffer should be at least 256 bytes long. This used to use
// a std::string but it worked about 50% slower, so this is somehow 
// unsafe but a lot faster.
uint32_t DNS::compose_name(const uint8_t* ptr, char* out_ptr) const {
    const uint8_t* start_ptr = ptr;
    const uint8_t* end = &records_data_[0] + records_data_.size();
    const uint8_t* end_ptr = 0;
    char* current_out_ptr = out_ptr;
    while (*ptr) {
        // It's an offset
        if ((*ptr & 0xc0)) {
            if (ptr + sizeof(uint16_t) > end) {
                throw malformed_packet();
            }
            uint16_t index;
            memcpy(&index, ptr, sizeof(uint16_t));
            index = Endian::be_to_host(index) & 0x3fff;
            // Check that the offset is neither too low or too high
            if (index < 0x0c || (&records_data_[0] + (index - 0x0c)) >= end) {
                throw malformed_packet();
            }
            // We've probably found the end of the original domain name. Save it.
            if (end_ptr == 0) {
                end_ptr = ptr + sizeof(uint16_t);
            }
            // Now this is our pointer
            ptr = &records_data_[index - 0x0c];
        }
        else {
            // It's a label, grab its size.
            uint8_t size = *ptr;
            ptr++;
            if (ptr + size > end || current_out_ptr - out_ptr + size + 1 > 255) {
                throw malformed_packet();
            }
            // Append a dot if it's not the first one.
            if (current_out_ptr != out_ptr) {
                *current_out_ptr++ = '.';
            }
            copy(ptr, ptr + size, current_out_ptr);
            current_out_ptr += size;
            ptr += size;
        }
    }
    // Add the null terminator.
    *current_out_ptr = 0;
    if (!end_ptr) {
        end_ptr = ptr + 1;
    }
    return end_ptr - start_ptr;
}
开发者ID:simple555a,项目名称:libtins,代码行数:51,代码来源:dns.cpp

示例6: main

int main()
  { // demonstrate match_results::format
  string result("The URL '");
  string tail("' was found.");
  regex rgx("http://([^/: ]+)");
  string text("The site http://www.petebecker.com has"
    " useful information.");
  smatch match;
  if (regex_search(text, match, rgx))
    { // show result of successful match
    copy(tail.begin(), tail.end(),
      match.format(back_inserter(result), "$&"));
    cout << result << '\n';
    }
  return 0;
  }
开发者ID:abo321,项目名称:books-code,代码行数:16,代码来源:returned.cpp

示例7: main

int main()
{
	istream_iterator<int>int_it(cin);		//reads ints from cin
	istream_iterator<int>int_eof;			//end iterator value
	vector<int>v(int_it, int_eof);			//initialize v by reading cin

	sort(v.begin(), v.end());
	ostream_iterator<int>out(cout, " ");		//writes ints to cout
	unique_copy(v.begin(), v.end(), out);		//write unique elements to cout
	cout << endl;							//write a newline after the output
	ofstream out_file("data");		//writes int to named file
	ostream_iterator<int>out_iter(out_file, " ");
	copy(v.begin(), v.end(), out_iter);
	out_file << endl;		//write a newline at end of the file
	getchar();
}
开发者ID:Larry955,项目名称:learnCPP,代码行数:16,代码来源:iostream-iter.cpp

示例8: assert

T*
newCopy(const T *src, size_t src_size, size_t dest_size)
{
   assert(dest_size >= src_size);
   T *dest = new T[dest_size];
   try
   {
      copy(src, src + src_size, dest);
   }
   catch (...)
   {
      delete[] dest;
      throw;
   }
   return dest;
}
开发者ID:testflyjets,项目名称:cpp4,代码行数:16,代码来源:hw2.cpp

示例9:

DocumentInfo& DocumentInfo::operator=(const DocumentInfo& other)
{
	if (this != &other)
	{
		m_title = other.m_title;
		m_location = other.m_location;
		m_type = other.m_type;
		m_language = other.m_language;
		m_timestamp = other.m_timestamp;
		m_labels.clear();
		copy(other.m_labels.begin(), other.m_labels.end(),
			inserter(m_labels, m_labels.begin()));
	}

	return *this;
}
开发者ID:BackupTheBerlios,项目名称:pinot-svn,代码行数:16,代码来源:DocumentInfo.cpp

示例10: first_permutation

 void first_permutation(int idx){
     char p[16]={};
     char pp[16]={};
     for ( int i=0; i<len; ++i ) 
        p[i] = i;
     for ( int i=len-1; i>0; --i ) {
         int d = idx / fact[i];
         count[i] = d;
         idx = idx % fact[i];
         copy( &p[0], &p[i+1], &pp[0] );
         for ( int j=0; j<=i; ++j ){
             p[j] = j+d <= i ? pp[j+d] : pp[j+d-i-1];
         }
     }
     this->p.assign(p, 16);
 }
开发者ID:CCJY,项目名称:coliru,代码行数:16,代码来源:main.cpp

示例11: URI

/**
 * @brief Converts a url into a local filename.
 *
 * @retval fn   a character buffer to hold the local filename.
 * @param nfn   the number of elements in the buffer @p fn points to.
 */
bool doc2::filename(char * fn, const size_t nfn) {
    using std::copy;
    using std::string;

    fn[0] = '\0';

    const char * s = 0;

    const std::string protocol = this->url_protocol();

    if (protocol == "file") {
# ifdef _WIN32
        string name = URI(this->url_).getPath().substr(1);
# else
        string name = URI(this->url_).getPath();
# endif
        size_t len = (name.length() < (nfn - 1))
                   ? name.length()
                   : nfn - 1;
        copy(name.begin(), name.begin() + len, fn);
        fn[len] = '\0';
        return true;
    } else if (protocol == "http") {
        //
        // Get a local copy of http files.
        //
        if (this->tmpfile_) {    // Already fetched it
            s = this->tmpfile_;
        } else if ((s = the_system->http_fetch(this->url_.c_str()))) {
            tmpfile_ = new char[strlen(s)+1];
            strcpy(tmpfile_, s);
            free(const_cast<char *>(s));        // assumes tempnam or equiv...
            s = tmpfile_;
        }
    }
    // Unrecognized protocol (need ftp here...)
    else {
        s = 0;
    }

    if (s) {
        strncpy( fn, s, nfn-1 );
        fn[nfn-1] = '\0';
    }

    return s && *s;
}
开发者ID:Triptofano,项目名称:basAR,代码行数:53,代码来源:doc.cpp

示例12: explode_by_first_of

void explode_by_first_of(const std::string& text, const std::string& separator, std::vector<std::string>& results) {
	std::string::size_type found;
	std::string copy(text);
	do {
		found = copy.find_first_of(separator);
		if(found > 0){
			results.push_back(copy.substr(0, found));
		}
		copy = text.substr(found + 1);
	}
	while(found != std::string::npos);

	if(results.empty()) {
		results.push_back(text);
	}
	return;
}
开发者ID:Theosis,项目名称:SPIRLe,代码行数:17,代码来源:preprocessor.cpp

示例13: main

int main(int argc, const char * argv[]) {
    
    ifstream in(argv[1]);
    vector<string> lines;
    
    copy(istream_iterator<string>(in),
         istream_iterator<string>(),
         back_inserter(lines));
    
    in.close();
    
    for(int i = 0; i < lines.size(); ++i){
        cout << sumOfDigits(strToInt(lines[i])) << "\n";
    }
    
    return 0;
}
开发者ID:spg63,项目名称:codeChallenge,代码行数:17,代码来源:sumOfDigits.cpp

示例14: explode

void explode(const string& text, const string& separator, vector<string>& results) {
	string::size_type found;
	string copy(text);
	const string::size_type separator_size = separator.length();
	do {
		found = copy.find(separator);
		if(found > 0){
			results.push_back(copy.substr(0, found));
		}
		copy = copy.substr(found + separator_size);
	}
	while(found != string::npos);

	if(results.empty()) {
		results.push_back(text);
	}
	return;
}
开发者ID:Theosis,项目名称:SPIRLe,代码行数:18,代码来源:preprocessor.cpp

示例15: handleRequest

void Server::handleRequest(shared_ptr<tcp::socket> socket, Logger log) {
  // ProfilerStart("/home/sowa/local_workspace/pje/log/server.perf");
  Server* server = this;
  vector<char> buffer(1024*1024);
  error_code error;
  socket->read_some(boost::asio::buffer(buffer), error);
  string request(buffer.size(), 0);
  copy(buffer.begin(), buffer.end(), request.begin());
  string remoteIp = socket->remote_endpoint().address().to_string();
  log.info("received request from " + remoteIp);
  string query = server->retrieveQuery(request);
  log.debug("query: \"" + query + "\"");
  string command = server->retrieveCommand(query);
  StrStrMap args = server->retrieveArgs(query, server->workDir());
  string argsString = "{";
  for (StrStrMap::const_iterator i = args.begin();
       i != args.end();
       ++i) {
    argsString += i->first + ": " + i->second + ", ";
  }
  argsString = argsString.substr(0, argsString.size() - 2);
  argsString += "}";
  log.info("executing command <" + command + "> with args " + argsString);
  int tries = 10;
  while (tries) {
    try {
      Command::execute(*server, socket, command, args, log);
      tries = 0;
    } catch(const std::bad_alloc&) {
      --tries;
      if (tries) {
        _log.error("not enough memory to complete task: retrying");
        boost::this_thread::sleep(boost::posix_time::seconds(3));
      } else {
        _log.error("not enough memory to complete task: giving up");
      }
    }
  }
  socket->close();
  // ProfilerStop();
}
开发者ID:eamsen,项目名称:transit-planner,代码行数:41,代码来源:Server.cpp


注:本文中的std::copy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。