arrays - Can someone show me how to modify a txt file in c++ ? ( i`m working in codeblocks) -


so have txt file this:

3/1995 13,25,16,14

4/1995 36,1,24,48

5/1996 39,46,35,2

233/1996 14,16,25,12

and want modify this, in txt file:

13,25,16,14

36,1,24,48

39,46,35,2

14,16,25,12

i want transform them char int , put them in 2d vector. tried far:

#include<iostream> #include<fstream> #include<cstring>  using namespace std;  static const int width = 10; static const int height = 50;         int main() {     char level[height][width];      ifstream file;     file.open("new.txt");       for(int = 0; < height; i++)     {         for(int j = 0; j < width; j++)         {           file>>level[i][j];          cout<<level[i][j];         }cout<<endl;     }        return 0; } 

and doesn`t read blank space messes everything.

in order gather characters including white spaces, advise use "get" instead of << operator.

edit : or getline suggested

in order apply change describe, it's quite easy each line made out of 2 string , want keep second 1 only.

so you'd have do, every line, file >> "a string" >> "a string"; (you use same), , file want write result : file2 << "a string"; (the second 1 use if not same)

note : there better ways it, easier came mind


Comments

Popular posts from this blog

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

wordpress - (T_ENDFOREACH) php error -

Using django-mptt to get only the categories that have items -