Practical Guide to STL

C++二维vector不是二维数组:内存模型与实操指南 在C++中,vector<vector<T>>常被误认为等价于二维数组,但其本质是‘一维vector,每个元素为独立可变长vector’的嵌套结构。它不保证内存连续,支持锯齿状布局,具备行级动态扩容能力,适用于不确定规模、需频繁增删的场景。理解其底层内存分配(外层存指针、内层各自管理堆内存)、初始化契约(如vector<vector<int>>(R, vector<int>(C))触发R次独立构造)及访问语义([]无检查、at()带异常),是避免越界崩溃、深拷贝误用和性能陷阱的关键。本文聚焦初学者高频踩坑点 阅读详情
   
Introduction
STL (Standard Template Library) is a good skill for anyone programming C++ in the modern day. I must say that it takes some getting used to, i.e. there is a fairly steep learning curve, and some of the names that are used are not very intuitive (perhaps because all of the good names had been used up). The upside is once learned they will save you headaches down the road. Compared to MFC containers, they are more flexible and powerful.
Listed advantages:
Can sort and search easily
They are safer and easier to debug
You can understand code written by the UNIX crowd.
It is another acronym to add to your resume
Background
This guide has been written so that the reader can get a running start at this challenging part of computer science, without having to wade through the endless mass of jargon and stifling exactitude that STL'er have created for their own amusement.
Using the Code
The code here is mainly instructive on the practical ways to use STL.
Definitions
Template - A macro for classes (and structures and data types and functions). Sometimes called a cookie cutter. Also formally known as generic - a template of a class is called a generic class. A template of a function is called, wait for it, a generic function.
STL - Standard Template Library, templates written by a bunch of smart people, now used by everyone part of the C++ standard language.
Container - A class that holds data. STL examples are vectors, sets, maps, multimaps, and deques.
Vector - Your basic array template. It is a container.
Iterator - A fancy word for a pointer to an element inside an STL container. It does other stuff too.
Hello World Program
I always wanted to write one and here is my golden 24 karet opportunity: a hello world program. This transfers a char string into a vector of characters and then displays the string one character at a time. A vector is your basic garden variety array-like template. Probably, about half of all STL containers are vectors, so if you grasp this program, you are half way to a complete understanding of STL.
 Collapse
// Program: Vector Demo 1
// Purpose: To demonstrate STL vectors

// #include "stdafx.h" - include if you use pre compiled headers
#include <vector>  // STL vector header. There is no ".h"
#include <iostream>  // for cout
using namespace std;  // Ensure that the namespace is set to std

char* szHW = "Hello World"; 
// This is - as we all know - a character array,
// terminated with a null character

int main(int argc, char* argv[])
{
  vector <char> vec;  // A vector (STL array) of characters

  // Define an iterator for a vector of characters - this is always
  // scoped to within the template
  vector <char>::iterator vi;
  // Initialize the character vector, loop through the string,
  // placing the data in the vector character by character until
  // the terminating NULL is reached
  char* cptr = szHW;  // Start a pointer on the Hello World string
  while (*cptr != '/0')
  {  vec.push_back(*cptr);  cptr++;  }
  // push_back places the data on the back of the vector
  // (otherwise known as the end of the vector)

  // Print each character now stored in the STL array to the console
  for (vi=vec.begin(); vi!=vec.end(); vi++) 
  // This is your standard STL for loop - usually "!="
  // is used in stead of "<"
  // because "<" is not defined for some containers. begin()
  // and end() retrieve iterators
  // (pointers) to the beginning of the vector and to the end of vector
  {  cout << *vi;  }  // Use the indirection operator
           // (*) to extract the data from the iterator
  cout << endl;  // No more "/n"

  return 0;
}
push_back is the standard function for putting data into a vector or deque. insert is a similar function and does much the same, and works with all containers, but is more complicated. The end() is actually the end plus one, to allow the loop to operate properly - it actually points to the point just beyond the limits of the data. Just like in a regular loop in which you say for (i=0; i<6; i++) {ar[i] = i;} - ar[6] does not exist, but it is never reached in the loop so it does not matter.
STL Annoyance #1:
One of the first annoyances of STL makes itself known. To initialize it with data is more difficult than is the case in C/C++ arrays. You basically must do it element by element, or first initialize an array and then transfer it. People are working on this I understand.
 Collapse
// Program: Initialization Demo
// Purpose: To demonstrate initialization of STL vectors

#include <cstring>  // same as <string.h>
#include <vector>
using namespace std;
int ar[10] = {  12, 45, 234, 64, 12, 35, 63, 23, 12, 55  };
char* str = "Hello World";
int main(int argc, char* argv[])
{
  vector <int> vec1(ar, ar+10);
  vector <char> vec2(str, str+strlen(str));
  return 0;
}
In programming, there are many ways of doing the same task. Another way to fill a vector is to use the more familiar square brackets, like so:
 Collapse
// Program: Vector Demo 2
// Purpose: To demonstrate STL vectors with
// counters and square brackets

#include <cstring>
#include <vector>
#include <iostream>
using namespace std;
char* szHW = "Hello World";
int main(int argc, char* argv[])
{
  vector <char> vec(strlen(sHW));
  // The argument initializes the memory footprint
  int i, k = 0;
  char* cptr = szHW;
  while (*cptr != '/0')
  {  vec[k] = *cptr;  cptr++;  k++;  }
  for (i=0; i<vec.size(); i++)
  {  cout << vec[i];  }
  cout << endl;
  return 0;
}
This example is cleaner, but allows you less control of the iterator, and has an extra integer counter, and you must explicitly set the memory footprint.
Namespaces
Hand in hand with STL is the concept of Namespaces. STL is defined within the std namespace. There are 3 ways to specify it:
USE that namespace, near the top of all files, but below headers.
 Collapse
using namespace std;
This is the simplest and best for simple projects, limits you to the std namespace, anything you add is improperly put in the std namespace (I think you go to heck for doing this).
Specify each and every template before use (like prototyping)
 Collapse
using std::cout;
using std::endl;
using std::flush;
using std::set;
using std::inserter;
This is slightly more tedious, although a good mnemonic for the functions that will be used, and you can interlace other namespaces easily.
EVERY time you use a template from the std namespace, use the std scope specifier.
 Collapse
typedef std::vector<std::string> VEC_STR;
This is tedious but the best way if you are mixing and matching lots of namespaces. Some STL zealots will always use this and call anyone evil who does not. Some people will create macros to simplify matters.
In addition, you can put using namespace std within any scope, for example, at the top of a function or within a control loop.
Some Tips
To avoid an annoying error code in debug mode, use the following compiler pragma:
 Collapse
#pragma warning(disable: 4786)
Another gotcha is: you must make sure that the spaces are placed between your angle brackets and the name. This is because >> is the bit shift operator, so:
 Collapse
vector <list<int>> veclis;
will give an error. Instead, write it:
 Collapse
vector <list <int> > veclis;
to avoid compilation errors.
Another Container - The set
This is the explanation lifted from the MS help file of the set: "The template class describes an object that controls a varying-length sequence of elements of type const Key. Each element serves as both a sort key and a value. The sequence is represented in a way that permits lookup, insertion, and removal of an arbitrary element with a number of operations proportional to the logarithm of the number of elements in the sequence (logarithmic time). Moreover, inserting an element invalidates no iterators, and removing an element invalidates only those iterators that point at the removed element."
An alternate, more practical, definition is: A set is a container that contains all unique values. This is useful for cases in which you are required to collect the occurrence of value. It is sorted in an order that is specified at the instantiation of the set. If you need to store data with a key/value pair, then a map is a better choice. A set is organized as a linked list, is faster than a vector on insertion and removal, but slightly slower on search and addition to end.
An example program would be:
 Collapse
// Program: Set Demo
// Purpose: To demonstrate STL sets

#include <string>
#include <set>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
  set <string> strset;
  set <string>::iterator si;
  strset.insert("cantaloupes");
  strset.insert("apple");
  strset.insert("orange");
  strset.insert("banana");
  strset.insert("grapes");
  strset.insert("grapes"); 
   // This one overwrites the previous occurrence
  for (si=strset.begin(); si!=strset.end(); si++) 
  {  cout << *si << " ";  }
  cout << endl;
  return 0;
}
// Output: apple banana cantaloupes grapes orange
If you want to become an STL fanatic, you can also replace the output loop in the program with the following lines.
 Collapse
copy(strset.begin(), strset.end(), ostream_iterator<string>(cout, " "));
While instructive, I find this personally less clear and prone to error. If you see it, now you know what it does.
All the STL Containers
Containers pre-date templates and are computer science concepts that have been incorporated into STL. The following are the seven containers implemented in STL.
vector - Your standard safe array. It is expanded in the "front" direction only.
deque - Functionally the same as a vector. Internally, it is different. It can be expanded in both the front and back.
list - Can only be traversed one step at time. If you are already familiar with the concept of a list, an STL list is doubly linked (contains pointer to both the previous and next value).
set - contains unique values that are sorted.
map - sorted set of paired values, one of which is the key on which sorts and searches occur, and the value which is retrieved from the container. E.g. instead of ar[43] = "overripe", a map lets you do this ar["banana"] = "overripe". So if you wanted to draw up a bit of information keyed on full name is easily done.
multiset - same as a set, but does not necessarily have unique values.
multimap - same as a map, but does not necessarily have unique keys.
Note: If you are reading the MFC help then you will also come across the efficiency statement of each container. I.E. (log n * n) insertion time. Unless you are dealing with very large number of values, you should ignore this. If you start to get a noticeable lag or are dealing with time critical stuff then you should learn more about the proper efficiency of various containers.
How to Use a Map with some Class
The map is a template that uses a key to obtain a value.
Another issue is that you will want to use your own classes instead of data types, like int that has been used up to now. To create a class that is "template-ready", you must be ensure that the class contains certain member functions and operators. The basics are:
default constructor (empty, usually)
copy constructor
overload "="
You would overload more operators as required in a specific template, for example, if you plan to have a class that is a key in a map you would have to overload relational operators. But that is another story.
 Collapse
// Program: Map Own Class
// Purpose: To demonstrate a map of classes

#include <string>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
class CStudent
{
public :
  int nStudentID;
  int nAge;
public :
  // Default Constructor - Empty
  CStudent()  {  }
  // Full constructor
  CStudent(int nSID, int nA)  {  nStudentID=nSID; nAge=nA;  }
  // Copy constructor
  CStudent(const CStudent& ob) 
    {  nStudentID=ob.nStudentID; nAge=ob.nAge;  }
  // Overload =
  void operator = (const CStudent& ob) 
    {  nStudentID=ob.nStudentID; nAge=ob.nAge;  }
};
int main(int argc, char* argv[])
{
  map <string, CStudent> mapStudent;
  mapStudent["Joe Lennon"] = CStudent(103547, 22);
  mapStudent["Phil McCartney"] = CStudent(100723, 22);
  mapStudent["Raoul Starr"] = CStudent(107350, 24);
  mapStudent["Gordon Hamilton"] = CStudent(102330, 22);
  // Access via the name
  cout << "The Student number for Joe Lennon is " <<
    (mapStudent["Joe Lennon"].nStudentID) << endl;
  return 0;
}
TYPEDEF
If you like to use typedef, this an example:
 Collapse
typedef set <int> SET_INT;
typedef SET_INT::iterator SET_INT_ITER
One convention is to make them upper case with underscores.
ANSI / ISO string
ANSI/ISO strings are commonly used within STL containers. It is your standard string class, widely praised except for its deficiency of no format statement. You must instead use << and the iostream codes (dec, width, etc.) to string together your string.
Use c_str() to retrieve a character pointer, when necessary.
Iterators
I said that iterators are pointers, but there is more. They look like pointers, act like pointers, but they are actually embedded in which the indirection operator (unary *) and -> have been overloaded to return a value from the container. It is a bad idea to store them for any length of time, as they usually invalid after a value has been added or removed from a container. They are something like handles in this regard. The plain iterator can be altered, so that the container is to be traversed in different ways:
iterator - For any container other than the vector, you can only step one at a time in a forward direction through the container. That is you can only use the ++ operator, not the -- or += operator on it. For vector only you can use any of +=, --, -=, ++, and all the comparison operators <, <=, >, >=, ==, !=.
reverse_iterator - If you want to step backwards instead of forwards through a non-vector container, replace iterator with reverse_iterator, begin() with rbegin(), and end() with rend(), ++ will then traverse backwards.
const_iterator - a forward iterator that returns a const value. Use this if you want to make it clear that this points to a read-only value.
const_reverse_iterator - a reverse iterator that returns a const value.
Sorting Order in Sets and Maps
Templates have other parameters besides the type of value. You can also pass callback functions (known as predicates - this is a function of one argument that returns a bool value). For example, say you want a set of strings that are automatically sorting in ascending order. You would simply create a set class in this way:
 Collapse
set <int, greater<int> > set1
greater <int> is another template for a function (generic function) which is used to sort values, as they are placed into the container. If you wanted the set to be sorted in descending order, you would write:
 Collapse
set <int, less<int> > set1
There are many other cased you must pass a predicate as parameter to the STL class, in algorithms, described below.
STL Annoyance #2 - Long Error Messages
The templated names get expanded for the compiler, so when the compiler chokes on something, it spits out extremely long error messages that are difficult to read. I have found no good way around this. The best is to develop the ability to find and focus on the end of the error code where the explanation is located. Another related annoyance: if you double click on the template error, it will take you to the point in the code within the template code, which is also difficult to read. Sometimes, it is best just to carefully re-examine your code, and ignore the error messages completely.
Algorithms
Algorithms are functions that apply to templates. This is where the real power of STL starts to show up. You can learn a few function names that usually apply to most of the template containers. You can sort, search, manipulate, and swap with the greatest of ease. They always contain a range within which the algorithm performs. E.g.: sort(vec.begin()+1, vec.end()-1) sorts everything but the first and last values.
The container itself is not passed to the algorithm, just two iterators from the container that bookend a range. In this way, algorithms are not restricted by containers directly, but by the iterators supported by that specific algorithm. In addition, many times you will also pass a name of a specially prepared function (those afore mentioned predicates) as an argument. You can even pass plain old values.
Example of algorithms in play:
 Collapse
// Program: Test Score
// Purpose: To demonstrate the use of algorithm
// with respect to a vector of test scores

#include <algorithm>  // If you want to use an
   // algorithm this is the header used.
#include <numeric>  // (For Accumulate)
#include <vector>
#include <iostream>
using namespace std;
int testscore[] = {67, 56, 24, 78, 99, 87, 56};
// predicate that evaluates a passed test
bool passed_test(int n)
{
  return (n >= 60);
}
// predicate that evaluates a failed test
bool failed_test(int n)
{
  return (n < 60);
}
int main(int argc, char* argv[])
{
  int total;
  // Initialize a vector with the data in the testscore array
  vector <int> vecTestScore(testscore,
     testscore + sizeof(testscore) / sizeof(int));
  vector <int>::iterator vi;
  // Sort and display the vector
  sort(vecTestScore.begin(), vecTestScore.end());
  cout << "Sorted Test Scores:" << endl;
  for (vi=vecTestScore.begin(); vi != vecTestScore.end(); vi++)
  {  cout << *vi << ", ";  }
  cout << endl;
  // Display statistics

  // min_element returns an _iterator_ to the
  // element that is the minimum value in the range
  // Therefor * operator must be used to extract the value
  vi = min_element(vecTestScore.begin(), vecTestScore.end());
  cout << "The lowest score was " << *vi << "." << endl;
  // Same with max_element
  vi = max_element(vecTestScore.begin(), vecTestScore.end());
  cout << "The highest score was " << *vi << "." << endl;
  // Use a predicate function to determine the number who passed
  cout << count_if(vecTestScore.begin(), vecTestScore.end(), passed_test) <<
    " out of " << vecTestScore.size() <<
    " students passed the test" << endl;
  // and who failed
  cout << count_if(vecTestScore.begin(),
    vecTestScore.end(), failed_test) <<
    " out of " << vecTestScore.size() <<
    " students failed the test" << endl;
  // Sum the scores
  total = accumulate(vecTestScore.begin(),
     vecTestScore.end(), 0);
  // Then display the Average
  cout << "Average score was " <<
    (total / (int)(vecTestScore.size())) << endl;
  return 0;
}
See you later, Allocator
These are used in the initialization stages of a template. They are mysterious behind the scenes type of creatures, and really only of concern if you are doing high level memory optimization, and are best considered to be black boxes. Usually, you never even specify them as they are default parameters that are generally not tinkered with. It is best to know what they are though in case they show up on one of those employment tests.
Derive or Embed Templates
Any way that you use a regular class, you can use an STL class.
It can be embedded:
 Collapse
class CParam
{
  string name;
  string unit;
  vector <double> vecData;
};
or used as a base class:
 Collapse
class CParam : public vector <double>
{
  string name;
  string unit;
};
Derivation should be used with some caution. It is up to you as to the form that fits your programming style.
Templates within Templates
To create a more complex data structure, you can nest a template within a template. It is best to typedef beforehand on the internal template as you will certainly need to use the inner template again.
 Collapse
// Program: Vector of Vectors Demo
// Purpose: To demonstrate nested STL containers

#include <iostream>
#include <vector>

using namespace std;
typedef vector <int> VEC_INT;
int inp[2][2] = {{1, 1}, {2, 0}}; 
  // Regular 2x2 array to place into the template
int main(int argc, char* argv[])
{
  int i, j;
  vector <VEC_INT> vecvec;
  // if you want to do this in all one step it looks like this
  // vector <vector <int> > vecvec;
 
  // Fill it in with the array
  VEC_INT v0(inp[0], inp[0]+2);  // passing two pointers
    // for the range of values to be copied to the vector
  VEC_INT v1(inp[1], inp[1]+2);
  vecvec.push_back(v0);
  vecvec.push_back(v1);
  for (i=0; i<2; i++)
  {
    for (j=0; j<2; j++)
    {
      cout << vecvec[i][j] << "  ";
    }
    cout << endl;
  }
  return 0;
}
// Output:
// 1 1
// 2 0
Although cumbersome to initialize, once completed and filled in, you have a 2 dimensional array that is indefinitely expandable (until memory space runs out). The same can be done for any combination of containers, as the situation requires.
Conclusion
STL is useful, but not without its annoyances. As the Chinese say: if you learn it, you will be like a tiger with the claws of a lion.
Related Links
Josuttis Website
Pretty Good Initialization Library
History
Submitted on March 23, 2004
Edited on April 2, 2004
License
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
About the AuthorJeff Bogan
 
Member  I shuffle tiny static charges on intricate wafers of silicon all day. Occupation:  Web Developer
Location:   Canada

Other popular STL articles:
An In-Depth Study of the STL Deque Container
This article presents an in-depth analysis of std::deque and offers guidance as to when to prefer using it as opposed to std::vector, by taking into consideration memory allocation and container performance.
Smart Pointers to boost your code
A beginner's introduction to the smart pointers provided by the boost library.
An STL-like bidirectional map
A template container implementing a bidirectional map that blends well with STL.
Upgrading an STL-based application to use Unicode.
Problems that developers will face when upgrading an STL-based application to use Unicode and how to solve them.
Can search_n be more efficient?
This article is discussing the efficiency of the most popular search_n implementations. Furthermore, it is introducing a new search_n specialization for random access iterators, which outruns by far the most commonly used implementations.
 
C++二维vector实战指南:内存布局、边界安全与性能优化 二维vector是C++中用于表示矩阵、图像、动态网格等二维数据结构的基础容器,其本质并非简单嵌套,而是由顶层容器管理多个独立连续内存块构成。理解其三层结构(外层vector + 中间vector对象 + 底层数据块)有助于规避缓存失效、越界访问和内存泄漏等常见问题。结合at()运行时检查与operator[]的零开销特性,可在开发阶段提升调试确定性,在生产环境保障性能可控。广泛应用于算法竞赛(如采药DP)、OpenCV图像处理、小游戏开发及嵌入式AI推理结果解析等场景。本文聚焦C++二维vector的核心 阅读详情

相关推荐

【信息科学与工程学】【数据科学】数据科学领域——第三篇 数学08 几何学00总篇

编号英文名称中文名称简要说明/归属1Foundations of Geometry几何基础公理化方法, Hilbert《几何基础》2Euclidean Geometry (Synthetic)欧几里得几何(综合法)《几何原本》传统3Analytic Geometry解析几何坐标方法, Descartes, Fermat4Plane Geometry平面几何三角形、圆、共点共线等经典问题5Solid Geometry立体几何三维空间中的图形与度量6Non-Euclidean Geometry非欧几何平行公设不

weixin_49199313的博客 220

STL实践指南 Practical Guide to STL

文章标题:STL实践指南Practical Guide to STL(上)原 作 者:Jeff Bogan  译者注 这是一篇指导您如何在Microsoft Visual Studio下学习STL并进行实践的文章。这篇文章从STL的基础知识讲起,循序渐进,逐步深入,涉及到了STL编写代码的方法、STL代码的编译和调试、命名空间(namespace)、STL中的ANSI / ISO字符串、各种不

回家念经(kv300)--编程之禅 2218

企业数字化转型AI大模型赋能智能体平台及AI场景应用规划方案(生态合作版).pptx

企业数字化转型AI大模型赋能智能体平台及AI场景应用规划方案(生态合作版).pptx

STL实践指南 Practical Guide to STL

STL实践指南 Practical Guide to STLQuote STL实践指南 Practical Guide to STLSTL简介STL (标准模版库,Standard Template Library)是当今每个从事C++编程的人需要掌握的一项不错的技术。我觉得每一个初学STL的人应该花费一段时间来熟悉它,比如,学习STL时会有急剧升降的学习曲线,并且有一些命名是

学海无涯 818

用 Coze 打造纯自动化 AI 情报助手

本文将引导您逐步构建一个简易的AI情报助手,从提示词到工作流,再到卡片消息,详细讲解了如何利用Coze平台开发自动化工具。过程简单易懂,何不亲自动手一试?如果您对此类内容感兴趣,敬请关注本作者。未来,我将带来更多精彩的AI工具教程,助您迅速掌握各类AI应用。在这个AI时代,让您领先一步。t=O83A2AGI.NET AI 教程 震撼!用 Coze 打造纯自动化 AI 情报助手震撼!

xinzhaobuxuan的博客 2532

matlab相机标定_实战 | 相机标定

点击“计算机视觉life”关注,置顶更快接收消息!本文阅读时间约5分钟什么是相机标定?我们为什么需要相机标定?相机标定就是确定相机内参和外参的过程,其结果精度会直接影响视觉系统后续工作的准确性。坐标系相机标定涉及到了四大坐标系,分别为:像素坐标系图像物理坐标系相机坐标系世界坐标系为了进行相机标定,必须已知世界坐标系中足够多的三维空间点坐标,找到这些空间点在图像中投影点的二维图像坐标,并建...

weixin_39747334的博客 765

A Practical Guide To STL

http://www.codeproject.com/vcpp/stl/PracticalGuideStl.asp Introduction STL (Standard Template Library) is a good skill for anyone programming C++ in the modern day. I must say that it takes some get...

weixin_30698297的博客 177

基于微信小程序的扫码签到系统源码

大等于jdk1.8,大于mysql5.5,idea(eclipse),微信开发者工具。代码注释齐全,没有多余代码,适合学习(毕设),二次开发,包含论文技术相关文档。签到管理:新增签到,点击查看码展示二维码(有时效性)springboot mybatis 小程序。签到管理:查看用户创建的签到,可删除。用户管理:查看注册用户信息,及删除。签到记录:查看用户签到记录:可删除。个人信息:展示个人信息,可修改。统计分析:查看用户,签到数量。签到记录:查看用户签到记录。登录注册(含授权登录)我的签到:查看签到记录。

wfuhui的博客 5226

STL实践指南 Practical Guide to STL[转]

STL实践指南 Practical Guide to STLQuote STL实践指南 Practical Guide to STLSTL简介STL (标准模版库,Standard Template Library)是当今每个从事C++编程的人需要掌握的一项不错的技术。我觉得每一个初学STL的人应该花费一段时间来熟悉它,比如,学习STL时会有急剧升降的学习曲线,并且有一些命名是

四毛的专栏 763

华大HC32F460从零到200MHz:手把手教你配置时钟系统(附避坑指南)

本文详细解析了华大HC32F460 MCU的时钟系统配置,从启动过程、时钟树分析到实战配置200MHz系统时钟。文章手把手指导开发者如何正确配置外部晶振、MPLL锁相环及总线分频,并提供了硬件检查、代码解读及常见问题排查的避坑指南,帮助用户从零构建稳定可靠的高性能时钟环境。

net55的博客 298

Python 爬取新浪财经 7x24(1): 下载数据

前言 最近在做一个需要很多财经数据的项目。于是想到可不可以通过爬虫来解决(尝试白嫖)。 提供财经数据的网站有很多个,其中比较靠谱和更新比较及时的应该是新浪7x24 live数据。 http://finance.sina.com.cn/7x24/?tag=0 这个问题有一定的难度,因为这个网页是动态加载的。每一次只会加载部分数据,而只有拉到底部才可以加载新的数据。 于是乎,我们要做的事情是: 下载数据 保存到数据库 本篇介绍如何下载数据。 代码 闲言少叙书归正文,代码的实现如下: import reque

ZJ_11701的博客 2906

Practical Guide to STL By Jeff Bogan

Introduction STL (Standard Template Library) is a good skill for anyone programming C++ in the modern day. I must say that it takes some getting used to, i.e. there is a fairly steep learning curve,

Tech is Online(物联网技术传播) 1205

Python 爬虫实战:拼多多商品评论情感分析(含词云生成与差评预警)

在电商行业竞争日益激烈的当下,商家对商品评论的分析需求愈发迫切。通过 Python 爬虫收集拼多多商品评论,并结合情感分析、词云可视化及差评预警技术,商家可精准洞察消费者反馈,优化商品与服务。本文将深度剖析从爬虫搭建到数据挖掘的关键环节,助力读者构建全流程电商评论分析系统。

yansideyucsdn的博客 1453

A practical guide to C++ serialization

A practical guide to C++ serialization In a nutshell, serialization consists of writing data and objects on a support (a file, a buffer, a socket), so that they can be reconstructed later in the

青青的专栏--C/C++ OOA/D Design Pattern 1080

Oracle EBS R12 主 / 辅助分类帐(主 / 辅助帐套)落地

本文提供了Oracle EBS R12主/辅助分类帐实施的全套文档模板,包含主帐套(法定帐套)和辅助帐套的完整配置清单、科目映射规则模板、4类典型调整分录示例(存货跌价、折旧差异、往来重分类、外币折算)以及税会/IFRS案例分录。重点阐述了主/辅助帐套的配置要点、SLA子分类帐关键配置、科目映射规则(一对一、多对一、重分类等类型)以及调整分录的自动生成逻辑。文档可直接用于项目实施,包含总体架构图、科目映射矩阵表、会计规则集配置等交付物,并附有Excel版模板便于直接使用。适用于需要实现多准则并行记账、税务调

金牌架构师 389

贝叶斯统计 [韦来生编]

贝叶斯(Bayes)统计是近几十年来迅速发展起来的数理统计的一个重要分支。贝叶斯方法与经典统计方法的主要不同之处是进行统计推断时除了利用样本信息外,还要利用参数的先验信息,因此可以提高统计推断或统计决策的效果。它在经济、金融、生物、医学、自然科学和社会科学等许多领域具有广泛的应用。贝叶斯方法的研究已渗透到了统计学的几乎所有领域。作者在给中国科学技术大学概率论与数理统计专业本科生开设的“数理统计”课程中有一章专门讲授“贝叶斯方法和统计决策理论”,近十年来也给中国科学技术大学概率统计专业研究生开设过几次“贝叶斯分析”课。本书是在对过去讲稿的内容作了适当的增减和调整的基础上完成的。  本书共分六章。第1章是绪论,介绍了贝叶斯统计的若干基本概念,同时对必要的数理统计的基础知识有重点地作了回顾。第二章介绍了确定先验分布的若干可供选择的方法。第三章介绍了几类常见统计模型参数的后验分布的主要结果和计算方法。第四章和第五章分别介绍了“贝叶斯统计推断”和“贝叶斯统计决策”的内容。第六章介绍了贝叶斯统计计算的若干方法,包括蒙特卡洛方法和马尔可夫链蒙特卡洛(MCMC)方法以及相关统计软件的简介。本书的每一章附右大量的例题和习题,书末附有常用的几个表格和部分习题解答供读者查用。  大约可在54学时内讲授本书的第1章至第六章的主要内容,教师可根据学时需要选讲本书第1章至第六章的部分内容。书中标“*”号的章节可略去不讲,留给读者作为阅读材料。第六章例题中的R代码和部分例题的数据文件等可从作者个人主页下载。  作者在编写本书的过程中参考了J.O.Berger教授的《统计决策论及贝叶斯分析》和茆诗松教授编写的《贝叶斯统计》等书中的一些内容,以及《贝叶斯分析》一书中由张伟平博士编写的有关贝叶斯统计计算的一些内容。在此表示衷心感谢。  本书编写准备过程中,中国科学技术大学统计与金融系的几个研究生帮助完成了本书部分中文的录入和排版,作者对他们的辛勤工作表示真诚的感谢。高等教育出版社为本书的出版给予了大力支持。在此一并致谢。

C++ 串行化——A practical guide to C++ serialization

Boost 有很多种 archive 格式,例如 Text, XML, and Binary archives,但是基本上只用 Text 和 XML,因为 Binary 的不保证 32bit/64bit 大端/小端等平台兼容性。 这里只介绍 Non Intrusive Version,也就是不需要修改原来的类定义:。 一个简答例子: #include &amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;boost/archive/te...

all for one,one for all 1535

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

C++程序设计之四书五经(下篇)

C++程序设计之四书五经(下篇)  我在上篇中“盘点”了TCPL和D&E以及入门教程、高效和健壮编程、模板和泛型编程等方面共十几本C++好书。冬去春来,让我们继续C++书籍精彩之旅 标准库  当我还在研究院工作时,与同院另外两家研究所合作开发过一个大型水利枢纽调度集成项目。我们三家软件系统之间都要相互通信。在调试通讯模块时,细心的客户(一名好学的系统管理员)发现对于同一通信规约的

cutter_point的专栏 691

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

[转载]一个图形爱好者的书架/白话说学计算机图形学

[转载]一个图形爱好者的书架/白话说学计算机图形学 1.一个图形爱好者的书架 原文地址:http://blog.youkuaiyun.com/nhsoft/archive/2004/06/23/22992.aspx          早几天看到有人把自己在大学四年的书列了出来.招来一顿怀疑.我是开发图形程序的.我现在也把我的书列出来.不怕大家怀疑吧.希望能有点启示作用. 绿色的是我看完了的。

在逆境中成长 1344
上一篇: 软件十年有感 --- 金蝶中间件公司CTO袁红岗
下一篇: 详解堆与栈
boby2010
博客等级 码龄17年 0粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值