我想要的只是一个 c++ 程序,它将读取一个 txt 文件,将每一行放入一个数组中,然后将副本打印到另一个 txt 文件中。这是我的代码...
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
string STRING ="";
string list[10000];
int i = 0;
ifstream infile;
infile.open ("C:/Users/Ryan/Desktop/data.txt");
ofstream myfile;
myfile.open ("C:/Users/Ryan/Desktop/data-2.txt");
while(!infile.eof()) // To get you all the lines.
{
getline(infile,STRING);
list[i]=STRING;
myfile<<list[i];
++i;
}
infile.close();
myfile.close();
return 0;
}
出于某种原因,尽管这样做,但每隔一行都会给我一堆时髦的中国符号。这是我的data.txt...
BPC 20101206 V 0.13 0.13 0.13 0
BPC 20101207 V 0.13 0.13 0.13 6500
BPC 20101208 V 0.13 0.13 0.13 0
BPC 20101209 V 0.13 0.125 0.125 117000
BPC 20101210 V 0.125 0.125 0.125 0
BPC 20101213 V 0.125 0.125 0.125 0
BPC 20101214 V 0.13 0.13 0.13 5000
BPC 20101215 V 0.13 0.13 0.13 290
BPC 20101216 V 0.125 0.115 0.115 24000
这是输出 data-2.txt ......
BPC 20101206 V 0.13 0.13 0.13 0
䈀倀䌀ऀ㈀ ㈀ 㜀ऀ嘀ऀ ⸀㌀ऀ ⸀㌀ऀ ⸀㌀ऀ㘀㔀 ഀ BPC 20101208 V 0.13 0.13 0.13 0
䈀倀䌀ऀ㈀ ㈀ 㤀ऀ嘀ऀ ⸀㌀ऀ ⸀㈀㔀ऀ ⸀㈀㔀ऀ㜀 ഀ BPC 20101210 V 0.125 0.125 0.125 0
䈀倀䌀ऀ㈀ ㈀㌀ऀ嘀ऀ ⸀㈀㔀ऀ ⸀㈀㔀ऀ ⸀㈀㔀ऀ ഀ BPC 20101214 V 0.13 0.13 0.13 5000
䈀倀䌀ऀ㈀ ㈀㔀ऀ嘀ऀ ⸀㌀ऀ ⸀㌀ऀ ⸀㌀ऀ㈀㤀 ഀ BPC 20101216 V 0.125 0.115 0.115 24000
有任何想法吗?