1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <iterator>
int main (){
std::vector<std::vector<int> > test = {{1,2,3,0,3},
{ 0,1,3,0,0},
{0,0,0,0,0},
{1,2,3,0,3},
{0,3,4,4,4},};
/*
for (int i = 0; i< 5; i++)
for (int k = 0; k <3; k++)
std::cout<<test[i][k];
std::cout<<std::endl;
std::cout<<test[4][3]; */
std::vector<int> f = {1,2,3,4,5,6,7,8,9,10};
int n = 0;
for (int i = 0; i < f.size(); i++)
{
if (n <= 2)
{
std::cout<<f[i]<<", "; n++;
}
else { n= 1; std::cout<<std::endl<<std::endl<<f[i]<<", ";
}
}
std::fstream file;
file.open("oppose.txt", std::ios::in | std::ios::out | std::ios::trunc);
if (file.is_open()){
int k = 0;
for (int i = 0; i < f.size(); i++)
{
if (k < 70)
{
file<<f[i]<<" "<<std::endl; k++;// ASKING FOR NEWLINE HERE GIVES GOOD RESULT
}
else { k=1;
file<<'n'<<'\n'<<'\n'<<f[i]<<" ,"; //ALL THE NEWLINES AM ASKING HERE ARE IGNORED! WHY?
}
}
std::cout<<"writing to file successful!";
}
else
{std::cout<<"could not write to file...";}
return 0;
}
|