473,470 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How do you get a 15x15 matrix using an ifstream

25 New Member
Expand|Select|Wrap|Line Numbers
  1. ifstream in1("txtxtxtx");
  2. int ct=0;
  3. int *p=new int[1300];
  4. int forever=1;
  5.  
  6. while(forever){ 
  7. in1 >> *(p+ct); 
  8.  
  9. if(*(p+ct) == -1) break;
  10. ct++; 
  11. } // WHILE LOOP
  12.  
  13. for(int i=0; i<ct; i++){
  14. cout << "\t" << *(p+i);
  15. if((ct)%15==0) cout << "\n";
  16. if((ct)%150==0) cout << "Enter to continue";
  17. } // FOR LOOP
  18. getch();
  19.  
  20. cout << "\n\n\tTotal data = " << ct;
  21. delete p; 
  22. in1.close(); 
So basically I'm trying to get a 15x15 matrix of the numbers from the text file I have and after a 15x15 matrix is printed I want the user to have the option to hit a key to continue. It prints all the numbers correctly, but it doesn't do the matrix in the way I would like it to. Any help is appreciated. Thanks
Feb 12 '10 #1
8 2416
whodgson
542 Contributor
What are you getting and what do you want?
Feb 12 '10 #2
lolcheelol
25 New Member
this is what i'm getting.

6 198 651 694 692 196 594 762 698
321 265 517 559 1010 648 131 621 968 513
544 30 863 827 688 311 758 284 729 845
285 164 896 343 1009 23 371 429 516 316
357 470 1007 789 181 530 56 148 214 726
1016 871 398 766 423 728 657 606 496 249
119 942 410 937 362 592 755 159 251 563
678 938 683 201 877 204 121 120 192 380
40 261 773 645 586 904 482 2 17 63
194 509 221 387 433 579 359 356 510 403
348 526 390 786 86 512 714 82 260 206
302 701 150 888 59 700 329 803 596 788
100 314 219 166 354 113 253 68 436 614
1012 1021 911 612 853 39 640 385 331 894
949 432 522 624 459 984 342 553 187 446
965 663 816 619 126 293 1022 545 748 27
824 564 5 836 442 636 197 608 826 450
381 957 671 70 236 550 146 763 55 310
572 488 93 313 575 1008 801 525 715 774
402 865 905 94 97 552 435 697 1018 13
882 931 494 838 244 118 807 231 941 224
860 295 186 777 397 389 754 338 898 946
468 1014 780 537 932 752 176 528 964 542
660 915 643 555 157 347 438 1020 388 878
950 444 62 337 585 987 315 641 976 422
373 527 178 966 587 969 64 274 607 851
639 303 693 498 476 167 569 106 395 649
995 379 50 369 102 1015 46 628 77 797
300 73 735 901 271 1002 42 577 222 142
740 140 887 676 275 702 890 521 779 713
180 202 200 506 91 561 484 372 885 143
99 237 848 243 234 821 971 103 574 116
15 35 912 308 744 925 908 289 1001 11
280 804 246 535 365 419 229 813 599 168
57 732 160 210 367 138 427 21 708 511
88 7 778 12 363 672 751 980 502 914
239 709 109 223 874 462 749 480 493 903
881 247 4 453 539 294 266 264 696 985
474 979 26 704 917 864 560 111 920 515
681 205 370 1 632 208 523 52 286 74
424 364 95 376 296 24 259 798 426 254
114 318 155 309 16 721 434 795 664 1011
320 125 549 207 658 165 615 742 605 741
98 341 487 669 399 8 642 829 25 616
72 83 986 943 916 217 129 185 880 899
855 844 182 108 475 440 378 602 305 133
737 782 799 654 595 298 769 787 584 923
334 1013 746 805 566 981 49 934 122 404
144 130 33 22 336 791 69 486 582 472
520 988 518 54 854 171 327 252 14 139
48 897 652 924 483 831 810 936 1019 747
921 497 392 682 837 479 292 820 884 112
828 333 907 28 944 618 918 765 951 790
601 361 469 647 213 546 720 919 190 152
665 567 282 514 989 134 411 416 841 428
731 461 75 1017 834 597 227 733 947 452
705 115 85 29 291 464 89 686 250 258
707 653 879 591 818 324 859 255 455 161
993 588 893 346 961 307 785 536 158 580
431 335 650 58 783 623 626 456 929 220
963 147 71 939 730 211 193 945 374 633
781 127 360 832 36 617 394 290 232 830
172 935 933 767 400 952 3 233 967 350
383 909 449 241 892 858 990 970 711 998
508 154 562 465 1023 533 630 784 634 124
802 188 323 598 978 955 495 739 876 718
216 297 84 273 151 557 866 576 646 954
629 611 352 842 991 812 445 344 529 558
80 554 953 287 110 104 870 822 136 270
891 413 420 466 603 583 10 240 668 719
556 299 662 622 96 568 926 76 677 900
775 170 699 792 930 330 600 107 958 776
609 153 927 761 972 268 256 638 301 983
750 997 538 541 540 137 604 531 817 500
430 174 690 61 1004 764 928 396 199 409
358 867 856 982 345 504 281 910 269 458
756 226 519 312 471 375 551 875 355 325
20 45 60 814 209 806 212 1006 625 457
895 637 117 203 183 532 328 283 53 712
886 145 245 490 391 873 716 43 685 218
163 175 667 906 9 548 366 81 809 996
815 589 679 571 66 179 823 332 745 973
418 695 492 808 230 415 412 962 760 79
437 191 691 278 408 794 710 590 242 478
340 101 248 578 825 570 959 796 377 18
833 132 135 38 195 680 386 852 263 507
78 34 351 627 768 977 659 304 505 999
674 835 501 173 473 547 51 177 736 703
65 257 414 491 565 353 843 184 734 793
87 725 811 368 994 872 401 913 489 32
235 1003 723 317 421 384 759 481 635 19
753 339 534 326 1005 922 31 675 770 847
406 156 463 277 960 800 189 306 123 477
447 37 485 684 322 439 460 724 41 902
228 738 454 349 656 620 743 940 105 581
655 267 869 631 593 149 771 276 543 441
407 262 1000 67 689 524 757 839 846 128
727 868 706 850 288 44 974 883 666 47
673 272 503 956 670 613 889 393 425 90
141 238 717 948 722 975 644 162 772 405
451 448 992 862 840 573 215 499 92 279
610 857 849 169 661 382 687 819 225 417

Total data = 1019
Complete

sorry for the large amount of text, but i wanted to be thorough.

i want this(obviously not the same numbers, but just making it easier for myself to show you)


6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648

Enter to continue...

then it just repeats. till the numbers finish outputting from the text file.
Feb 12 '10 #3
newb16
687 Contributor
The loop variable is i, but you always check for ct % something, that is constant throughout the loop.
Feb 12 '10 #4
lolcheelol
25 New Member
that doesn't make alot of sense to me because my count is telling me how many numbers i have...
Feb 12 '10 #5
newb16
687 Contributor
So why do you want to print next line after each number if total number of items divides by 15?
Feb 12 '10 #6
lolcheelol
25 New Member
so it looks like this in the output

6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648

Enter to continue...

not

6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
Enter to continue...

does my question make sense? i know my actual coding is right because i'm getting the numbers, i just would like to know why the matrix isn't working
Feb 12 '10 #7
newb16
687 Contributor
It's because _that_ part of coding that is responsible for making matrix _isn't_ right.
Feb 12 '10 #8
lolcheelol
25 New Member
so your saying it should be i instead of ct? i'm not really getting what your saying.
Feb 12 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Ben Ingram | last post by:
Hi all, I am writing a template matrix class in which the template parameters are the number of rows and number of columns. There are a number of reasons why this is an appropriate tradeoff for...
5
by: Jason | last post by:
Hello. I am trying to learn how operator overloading works so I wrote a simple class to help me practice. I understand the basic opertoar overload like + - / *, but when I try to overload more...
4
by: hall | last post by:
Hi. I ran across a bug in one of my problems and after spending some time tracking it down i found that the problem arose in a piece of code that essentially did this: ----------- ifstream...
3
by: Mike Alexeev | last post by:
Hi all, I have come across very strange behavior of the return value of the time() function. Below is the program to illustrate the problem: The value of NOW somehow changes after the call to the...
6
by: memocan | last post by:
#include <iostream> using namespace std; int x; //global variable matrix int main() { x= new float ; //initialize the size now }
20
by: Frank-O | last post by:
Hi , Recently I have been commited to the task of "translating" some complex statistical algorithms from Matlab to C++. The goal is to be three times as fast as matlab ( the latest) . I've...
5
by: Assertor | last post by:
Hi, all. Is there any way to create an instance of std::ifstream using std::string. (through std::ifstream's constructor or assignment operator or iterator, etc...) i.e. std::string str =...
2
by: isaac2004 | last post by:
hello i am trying to read an input file into a matrix, i have the following setup to get the file #include <iostream> #include <string> #include <fstream> using namespace std; int main()
1
nurulshidanoni
by: nurulshidanoni | last post by:
Dear all, my algorith is like this while(mor students) read studentID countexam=0 while (more examination) read examcode examID =get ExamID (examCode)
11
by: adramolek | last post by:
So... I'm trying to get used to using C++ ifstream (or ofstream) instead of stdio (although I'm having second thoughts). Anyways, I want to be able to display a meaningful error message if ifstream...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.