Cannot output a vector

What I am trying to do is get a number from a text document and print out the prime factorization of the number with a vector. If there is a better way to do what I am doing also let me know that too, I am trying to learn some better ways to do things. Also how to learn how to actually get a vector to print. First time I've tried using one.

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
#include <iostream>
#include <fstream> 
#include <vector> 
#include <string>

using namespace std;

vector<int> vectFactors;
string stringNum;
int intNum;
char wait4User;

int main () {
  ifstream myfile ("Prime.txt"); 
  if (myfile.is_open()) 
  {
   while ( myfile.good() ) 
    {
      getline (myfile,stringNum); 
    }
    int intNum = atoi(stringNum.c_str()); 
    myfile.close(); // Close the file  
  }
  else cout << "Unable to open file"; 
  
  if (intNum != 0)
  {
    while (intNum % 11 == 0)
    {
          intNum / 11;
          vectFactors.push_back(11);
    }
    while (intNum % 7 == 0)
    {
          intNum / 7;
          vectFactors.push_back(7);
    }
    while (intNum % 2 == 0)
    {
          intNum / 2;
          vectFactors.push_back(2);
    }
   
     cout << vectFactors;
    }
  cin >> wait4User;
  return 0;
}


Some of this code I have learned just recently, so some of it might be wrong too.

I should point out that cout << vectFactors; is the line it errors at.
Last edited on
1
2
for (size_t i = 0; i < vectFactors.size(); i++)
cout << vectFactors[i].str();
Topic archived. No new replies allowed.