以下のようなプログラムから始めて、動作が異なるかどうかを確認してください。また、エディターの動作を信頼するのではなく、「wc」などのツールを使用して実際の行数を取得することも検討してください。C++ に関する私の知識は時代遅れですが、これらの新しい文字列は、以下の私の最愛の人と同じように機能すると確信していchar *
ます。
#include <fstream>
using namespace std;
int main() {
ofstream out("stackoverflow-13957937.csv");
const char *separator = "";
const char *comma = ",";
for(int i=0; i<1000; i++) {
out << separator;
out << i*1.1f;
separator = comma;
}
out << endl;
return 0;
}
このプログラムは、コンマで区切られた 1000 個の浮動小数点数を 1 行に出力します。
chet@baconator:~$ g++ -Wall stackoverflow-13957937.cc -o stackoverflow-13957937
chet@baconator:~$ ./stackoverflow-13957937
chet@baconator:~$ 猫の stackoverflow-13957937.csv
0,1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9,11,12.1,13.2,14.3,15.4,16.5,17.6,18.7,19.8,20.9,22,23.1,24.2,25.3,26.4, 、 55,56.1,57.2,58.3,59.4,60.5,61.6,62.7,63.8,64.9,66,67.1,68.2,69.3,70.4,71.5,72.6,73.7,74.8,75.9,77,78.1,79.2,80.3,81.4, 82.5,83.6,84.7,85.8,86.9,88,89.1,90.2,91.3,92.4,93.5,94.6,95.7,96.8,97.9,99,100.1,101.2,102.3,103.4,104.5,105.6,106.7,108,107.8,1110. 112.2,113.3,114.4,115.5,116.6,117.7,118.8.8,119,121,122.1,123.2,124.3,125.4,126.5,127.6,128.7,129.8,8,133.133.1313,133.133.133.133.133.133.133.133.13.13.13.13.13 141.9,143,144.1,145.2,146.3,147.4,148.5,149.6,150.7,151.8,152.9,154,155.1,156.2,157.3,158.4,159.5,160.6,161.7,162.8,163.9,165,166.1,167.2,168.3,169.4,170.5,171.6, 172.7,173.8,174.9,176,177.1,178.2,179.3,180.4,181.5,182.6,183.7,184.8,185.9,187,188.1,189.2,190.3,191.4,192.5,193.6,194.7,195.8,196.9,198,1999999.1,200.2,201.3,201.22201.19999999999 212.3,213.4,214.5,215.6,216.7,217.8,218.9,220,221.1,222.2,223.3,224.4,225.5,226.6,227.7,228.8,229,9,231,232.2.2.2.2.2.2.2.2.2.2.2.2.29.2.2.29.2.29 242,243.1,244.2,245.3,246.4,247.5,248.6,249.7,250.8,251.9,253,254.1,255.2,256.3,257.4,258.5,259.6,260.7,261.8,262.9,264,265.1,266.2,267.3,268.4,269.5,270.6,271.7, 272.8,273.9,275,276.1,277.2,278.3,279.4,280.5,281.6,282.7,283.8,284.9,286,287.1,288.2,289.3,290.4,291.5,292.6,293.7,294.8,295.9,297,298.1,299.2,300.3,301.4,302.5, 303.6,304.7,305.8,306.9,308,309.1,310.2,311.3,312.4,313.5,314.6,315.7,316.8,317.9,319,320.1,321.2,3222.3,3323.4,324.5,31,31,31,31,31,317 334.4,335.5,336.6,337.7,338.8,339.9,341,342.1,343.2,344.3,345.4,346.5,347.6,348.7,349.8,350.9,352,353.1,354.2,355.3,356.4,357.5,358.6,359.7,360.8,361.9,363,364.1,365.2,366.3,367.4,368.5,369.6,370.7,371.8,372.9, 374,375.1,376.2,377.3,378.4,379.5,380.6,381.7,382.8,383.9,385,386.1,387.2,388.3,389.4,390.5,391.6,392.7,393.8,394.9,396,397.1,398.2,399.3,400.4,401.5,402.6,403.7, 404.8,405.9,407,408.1,409.2,410.3,411.4,412.5,413.6,414.7,415.8,416.9,418,419.1,420.2,421.3,422.4,423.5,424.6,425.7,426.8,427.9,429,430.1,431.2,432.3,433.4,434.5, 435.6,436.7,437.8,438.9,440,441.1,442.2,443.3,444.4,445.5,446.6,447.7,448.8,449.9,451,452.1,453.2,454.3,455.4,456.5,457.6,458.7,459.8,460.9,462,463.1,464.2,465.3, 466.4,467.5,468.6,469.7,470.8,471.9,473,474.1,475.2,476.3,477.4,478.5,479.6,480.7,481.8,482.9,484,485.1,486.2,487.3,488.4,489.5,490.6,491.7,492.8,493.9,495,496.1, 497.2,498.3,499.4,500.5,501.6,502.7,503.8,504.9,506,507.1,508.2,509.3,510.4,511.5,512.6,513.7,514.8,515.9,517,518.1,519.2,520.3,521.4,5222.5,523.6,6,524.7,525.8,8,8526.9,5528,5524.5524.5524.5.5528,5528 536.8,537.9,539,540.1,541.2,542.3,543.4,544.5,545.6,546.7,547.8,548.9,550,551.1,552.2,553.3,554.4,555.5,556.6,557.7,558.8,559.9,561,562.1,563.2,564.3,565.4,566.5, 567.6,568.7,569.8,570.9,572,573.1,574.2,575.3,576.4,577.5,578.6,579.7,580.8,581.9,583,584.1,585.2,586.3,587.4,588.5,589.6,590.7,591.8,592.9,594,595.1,596.2,597.3, 598.4,599.5,600.6,601.7,602.8,603.9,605,606.1,607.2,608.3,609.4,610.5,611.6,612.7,613.8,614.9,616,617.1,618.2,619.3,620.4,621.5,622.6,623.7,624.8,625.9,627,628.1, 629.2,630.3,631.4,632.5,633.6,634.7,635.8,636.9,638,639.1,640.2,641.3,642.4,6433.5,644.6,645.7,65,55.5.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.5 658.9,660,661.1,662.2,663.3,664.4,665.5,666.6,667.7,668.8,669.9,671,672.1,673.2,674.3,675.4,676.5,677.6,678.7,679.8,680.9,682,683.1,684.2,685.3,686.4,687.5,688.6,689.7,690.8,691.9,693,694.1,695.2,696.3,697.4,698.5,699.6, 700.7,701.8,702.9,704,705.1,706.2,707.3,708.4,709.5,710.6,711.7,712.8,713.9,715,716.1,717.2,718.3,719.4,720.5,721.6,722.7,723.8,724.9,726,727.1,728.2,729.3,730.4, 731.5,732.6,733.7,734.8,735.9,737,738.1,739.2,740.3,741.4,742.5,743.6,744.7,745.8,746.9,748,749.1,750.2,751.3,752.4,753.5,754.6,755.7,756.8,757.9,759,760.1,761.2, 762.3,763.4,764.5,765.6,766.7,767.8,768.9,770,771.1,772.2,773.3,774.4,775.5,776.6,777.7,778.8,779.9,781,782.1,783.2,784.3,785.4,786.5,787.6,788.7,789.8,790.9, 792,793.1,794.2,795.3,796.4,797.5,798.6,799.7,800.8,801.9,803,804.1,805.2,806.3,807.4,808.5,809.6,810.7,811.8,812.9,814,815.1,816.2,817.3,818.4,819.5,820.6,821.7, 822.8,823.9,825,826.1,827.2,828.3,829.4,830.5,831.6,832.7,833.8,834.9,836,837.1,838.2,839.3,840.4,841.5,842.6,843.7,844.8,845.9,847,848.1,849.2,850.3,851.4,852.5,853.6,854.7,855.8,856.9,858,859.1,860.2,861.3,862.4, 863.5,864.6,865.7,866.8,867.9,869,870.1,871.2,872.3,873.4,874.5,875.6,876.7,877.8,878.9,880,881.1,882.2,883.3,884.4,885.5,886.6,887.7,888.8,889.9,891,892.1,893.2, 894.3,895.4,896.5,897.6,898.7,899.8,900.9,902,903.1,904.2,905.3,906.4,907.5,908.6,909.7,7,910.8,919,91,91,919191919191919,913,913 924,925.1,926.2,927.3,928.4,929.5,930.6,931.7,932.8,933.9,935,936.1,937.2,938.3,939.4,940.5,941.6,942.7,943.8,944.9,946,947.1,948.2,949.3,950.4,951.5,952.6,953.7, 954.8,955.9,957,958.1,959.2,960.3,961.4,962.5,963.6,964.7,965.8,966.9,968,969.1,970.2,971.3,972.4,973.5,974.6,975.7,976.8,977.9,979,980.1,981.2,982.3,983.4,984.5, 985.6,986.7,987.8,988.9,990,991.1,992.2,993.3,994.4,995.5,996.6,997.7,998.8,999.9,1001,1002.1,1003.2,1004.3,1005.4,1006.5,1007.6,1008.7,1009.8,1010.9,1012,1013.1,1014.2.2,101.1111111111113.1013.10113.1013.1013.1013.1013.1013.1018 1023,1024.1,1025.2,1026.3,1027.4,1028.5,1029.6,1030.7,1031.8,1032.9,1034,1035.1,1036.2,1037.3,1038.4,1039.5,1040.6,1041.7,1042.8,1043.9,1045,1046.1,1047.2,1048.3,1049.4, 1050.5,1051.6,1052.7,1053.8,1054.9,1056,1057.1,1058.2,1059.3,1060.4,1061.5,1062.6,1063.7,10644.8,1065.9,1067,1068.1,1069.2,1072.1072.1072.1072.1072.1072 1078,1079.1,1080.2,1081.3,1082.4,1083.5,1084.6,1085.7,1086.8,1087.9,1089,1090.1,1091.2,1092.3,1093.4,1094.5,1095.6,1096.7,1098.9.1031.8,1032.9,1034,1035.1,1036.2,1037.3,1038.4,1039.5,1040.6,1041.7,1042.8,1043.9,1045,1046.1,1047.2,1048.3,1049.49.49.49.49.49.49.550.5,101.10.p.p.p.p.p.p.p.p.p.p.p.p.p.p.p.p.p.p.p.p.ph.p.p.2.10.10.10.10.10.10.10.10.10.10.10.108 1059.3,1060.4,1061.5,1062.6,1063.7,1064.8,1065.9,1067,1068.1,1069.2,1070.3,1071.4,1072.5,1073.6,1074.7,1075.8,1079,107.1111111111111111111076 1086.8,1087.9,1089,1090.1,1091.2,1092.3,1093.4,1094.5,1095.6,1096.7,1097.8,1098.91031.8,1032.9,1034,1035.1,1036.2,1037.3,1038.4,1039.5,1040.6,1041.7,1042.8,1043.9,1045,1046.1,1047.2,1048.3,1049.49.49.49.49.49.49.550.5,101.10.p.p.p.p.p.p.p.p.p.p.p.p.p.p.p.p.p.p.p.p.ph.p.p.2.10.10.10.10.10.10.10.10.10.10.10.108 1059.3,1060.4,1061.5,1062.6,1063.7,1064.8,1065.9,1067,1068.1,1069.2,1070.3,1071.4,1072.5,1073.6,1074.7,1075.8,1079,107.1111111111111111111076 1086.8,1087.9,1089,1090.1,1091.2,1092.3,1093.4,1094.5,1095.6,1096.7,1097.8,1098.9
chet@baconator:~$ wc stackoverflow-13957937.csv
1 1 5790 スタックオーバーフロー-13957937.csv
chet@baconator:~$
wc
出力は、行数 (1)、単語数 (1)、およびバイト数 (5790) であることに注意してください。
技術的には、行数には改行が含まれるため、最後の行が改行で終わらない場合は、実際の行数よりも 1 つ少なく報告されます。
ただし、ファイルが改行で終わっていない場合、後のプロンプトcat stackoverflow-13957937.csv
は同じ行になります。これを以下に示します。
chet@baconator:~$ echo -n '例--> '
例--> chet@baconator:~$