All I want is C ++ - a program that will read in a txt file, put each line in an array, and then print a duplicate copy to another txt file. Here is my code ...
#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; }
For some reason, while doing this, every other line gives me a bunch of funky Chinese characters. Here is my 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
But the output is 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
Any ideas?
source share