C++无法输出txt文件全部内容以及输出出现乱码的解决方法-创新互联

 在做数据结构的大作业时,发现在输出某篇文章时输出到某个位置就强制中止了,后面的代码也无法正常执行。

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:空间域名、虚拟主机、营销软件、网站建设、桥西网站维护、网站推广。

以下是代码和文本原文,出现问题的部分已经标记出来了。

The orange is the fruit of various citrus species in the family Rutaceae (see list of plants known as orange); it primarily refers to Citrus × sinensis, which is also called sweet orange, to distinguish it from the related Citrus × aurantium, referred to as bitter orange. The sweet orange reproduces asexually (apomixis through nucellar embryony); varieties of sweet orange arise through mutations.

The orange is a hybrid between pomelo (Citrus maxima) and mandarin (Citrus reticulata). The chloroplast genome, and therefore the maternal line, is that of pomelo. The sweet orange has had its full genome sequenced.

The orange originated in a region encompassing Southern China, Northeast India, and Myanmar,[8][9] and the earliest mention of the sweet orange was in Chinese literature in 314 BC. As of 1987, orange trees were found to be the most cultivated fruit tree in the world. Orange trees are widely grown in tropical and subtropical climates for their sweet fruit. The fruit of the orange tree can be eaten fresh, or processed for its juice or fragrant peel. As of 2012, sweet oranges accounted for approximately 70% of citrus production.

In 2019, 79 million tonnes of oranges were grown worldwide, with Brazil producing 22% of the total, followed by China and India.

Taxonomy and terminology
Main article: Citrus taxonomy
All citrus trees belong to the single genus Citrus and remain almost entirely interfertile. This includes grapefruits, lemons, limes, oranges, and various other types and hybrids. As the interfertility of oranges and other citrus has produced numerous hybrids and cultivars, and bud mutations have also been selected, citrus taxonomy is fairly controversial, confusing or inconsistent.[12][14] The fruit of any citrus tree is considered a hesperidium, a kind of modified berry; it is covered by a rind originated by a rugged thickening of the ovary wall.

Different names have been given to the many varieties of the species. Orange applies primarily to the sweet orange – Citrus sinensis (L.) Osbeck. The orange tree is an evergreen, flowering tree, with an average height of 9 to 10 m (30 to 33 ft), although some very old specimens can reach 15 m (49 ft). Its oval leaves, alternately arranged, are 4 to 10 cm (1.6 to 3.9 in) long and have crenulate margins. Sweet oranges grow in a range of different sizes, and shapes varying from spherical to oblong. Inside and attached to the rind is a porous white tissue, the white, bitter mesocarp or albedo (pith). The orange contains a number of distinct carpels (segments) inside, typically about ten, each delimited by a membrane, and containing many juice-filled vesicles and usually a few seeds (pips). When unripe, the fruit is green. The grainy irregular rind of the ripe fruit can range from bright orange to yellow-orange, but frequently retains green patches or, under warm climate conditions, remains entirely green. Like all other citrus fruits, the sweet orange is non-climacteric. The Citrus sinensis group is subdivided into four classes with distinct characteristics: common oranges, blood or pigmented oranges, navel oranges, and acidless oranges.

Other citrus groups also known as oranges are:

Mandarin orange (Citrus reticulata) is an original species of citrus, and is a progenitor of the common orange.
Bitter orange (Citrus aurantium), also known as Seville orange, sour orange (especially when used as rootstock for a sweet orange tree), bigarade orange and marmalade orange. Like the sweet orange, it is a pomelo x mandarin hybrid, but arose from a distinct hybridization event.
Bergamot orange (Citrus bergamia Risso), grown mainly in Italy for its peel, producing a primary essence for perfumes, also used to flavor Earl Grey tea. It is a hybrid of bitter orange x lemon.
Trifoliate orange (Poncirus trifoliata), sometimes included in the genus (classified as Citrus trifoliata). It often serves as a rootstock for sweet orange trees and other Citrus cultivars.

An enormous number of cultivars have, like the sweet orange, a mix of pomelo and mandarin ancestry. Some cultivars are mandarin-pomelo hybrids, bred from the same parents as the sweet orange (e.g. the tangor and ponkan tangerine). Other cultivars are sweet orange x mandarin hybrids (e.g. clementines). Mandarin traits generally include being smaller and oblate, easier to peel, and less acidic. Pomelo traits include a thick white albedo (rind pith, mesocarp) that is more closely attached to the segments.

Orange trees generally are grafted. The bottom of the tree, including the roots and trunk, is called rootstock, while the fruit-bearing top has two different names: budwood (when referring to the process of grafting) and scion (when mentioning the variety of orange).

History

Yellow Oranges and Green Tangerines by Zhao Lingrang, Chinese fan painting from the Song dynasty (NPM)
The sweet orange is not a wild fruit,[17] having arisen in domestication from a cross between a non-pure mandarin orange and a hybrid pomelo that had a substantial mandarin component. Since its chloroplast DNA is that of pomelo, it was likely the hybrid pomelo, perhaps a BC1 pomelo backcross, that was the maternal parent of the first orange.[7][40] Based on genomic analysis, the relative proportions of the ancestral species in the sweet orange is approximately 42% pomelo and 58% mandarin. All varieties of the sweet orange descend from this original cross, differing only by mutations selected for during agricultural propagation.[40] Sweet oranges have a distinct origin from the bitter orange, which arose independently, perhaps in the wild, from a cross between pure mandarin and pomelo parents. The earliest mention of the sweet orange in Chinese literature dates from 314 B.C.

In Europe, the Moors introduced the orange to the Iberian Peninsula which was known as Al-Andalus, with large scale cultivation starting in the 10th century as evidenced by complex irrigation techniques specifically adapted to support orange orchards. Citrus fruits — among them the bitter orange — were introduced to Sicily in the 9th century during the period of the Emirate of Sicily, but the sweet orange was unknown until the late 15th century or the beginnings of the 16th century, when Italian and Portuguese merchants brought orange trees into the Mediterranean area. Shortly afterward, the sweet orange quickly was adopted as an edible fruit. It also was considered a luxury item and wealthy people grew oranges in private conservatories, called orangeries. By 1646, the sweet orange was well known throughout Europe. Louis XIV of France had a great love of orange trees, and built the grandest of all royal Orangeries at the Palace of Versailles. At Versailles potted orange trees in solid silver tubs were placed throughout the rooms of the palace, while the Orangerie allowed year-round cultivation of the fruit to supply the court. When Louis condemned his finance minister, Nicolas Fouquet, in 1664, part of the treasures which he confiscated were over 1,000 orange trees from Fouquet's estate at Vaux-le-Vicomte.

Spanish travelers introduced the sweet orange into the American continent. On his second voyage in 1493, Christopher Columbus may have planted the fruit in Hispaniola. Subsequent expeditions in the mid-1500s brought sweet oranges to South America and Mexico, and to Florida in 1565, when Pedro Menéndez de Avilés founded St Augustine. Spanish missionaries brought orange trees to Arizona between 1707 and 1710, while the Franciscans did the same in San Diego, California, in 1769. An orchard was planted at the San Gabriel Mission around 1804 and a commercial orchard was established in 1841 near present-day Los Angeles. In Louisiana, oranges were probably introduced by French explorers.

Archibald Menzies, the botanist and naturalist on the Vancouver Expedition, collected orange seeds in South Africa, raised the seedlings onboard and gave them to several Hawaiian chiefs in 1792. Eventually, the sweet orange was grown in wide areas of the Hawaiian Islands, but its cultivation stopped after the arrival of the Mediterranean fruit fly in the early 1900s.

As oranges are rich in vitamin C and do not spoil easily, during the Age of Discovery, Portuguese, Spanish, and Dutch sailors planted citrus trees along trade routes to prevent scurvy.

Florida farmers obtained seeds from New Orleans around 1872, after which orange groves were established by grafting the sweet orange on to sour orange rootstocks.

Nutritional value and phytochemicals
Orange flesh is 87% water, 12% carbohydrates, 1% protein, and contains negligible fat (table). In a 100 gram reference amount, orange flesh provides 47 calories, and is a rich source of vitamin C, providing 64% of the Daily Value. No other micronutrients are present in significant amounts (table).

Oranges contain diverse phytochemicals, including carotenoids (beta-carotene, lutein and beta-cryptoxanthin), flavonoids (e.g. naringenin) and numerous volatile organic compounds producing orange aroma, including aldehydes, esters, terpenes, alcohols, and ketones.
Orange squeezer for making juice
Orange juice contains only about one-fifth the citric acid of lime or lemon juice 

代码和控制台输出

 

解决过程

 一开始我以为是读取txt的时候出现的问题,直到我试着通过str.length()去看看是不是拼接字符串时出现的问题时,发现并不是读取而是打印输出时出现的问题(拼接后的字符串长度与给定txt文件的长度是一致的,说明txt文件的读取和字符串的存取都是没问题的。)那么问题只可能是在cout即输出到控制台的过程中,程序碰到了某种错误而强制退出。

 我试想着是不是缓冲区溢出,超出了上限导致无法输出。但这篇文章只有9000多字,很明显不是这个问题。

 直到我先去解决控制台显示乱码问题时,发现只需要把txt文件的编码格式从UTF-8改为ANSI即可正常输出,同时打印的字符串也不会出现乱码。这里推测是因为原本txt的编码格式为UTF-8,而vs在cout时碰到了某个无法识别的字符编码便强制退出。

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


网站题目:C++无法输出txt文件全部内容以及输出出现乱码的解决方法-创新互联
分享URL:http://azwzsj.com/article/ddgcos.html