cout not printing

I can't seem to print using cout without <<endl.

I've tried using cout << flush and cout.flush() but to no avail.

What on earth is happening here?
Show code that reproduces the problem.
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
case 2:
	{
	cout << endl<<"9";

	ifstream loadpubkey;
	loadpubkey.open("PUBLICKEY.key");
	string PKn;
	string PKe;
	ofstream encryptfile ("ENCRYPTED.txt") ;

	mpz_t PKn1;
	mpz_t PKe1;


	if (loadpubkey.fail())
		cout << "Public key does not exist. Public key must be named PUBLICKEY.key";

	else
	{	
		
		getline (loadpubkey,PKn);
		getline (loadpubkey,PKe);

		mpz_init_set_str (PKn1,PKn.c_str(),10);
		mpz_init_set_str (PKe1,PKe.c_str(),10);

	}

	loadpubkey.close();

	std::ifstream in("plaintext.txt");
	std::stringstream buffer;
	string contents2;
	
	if (in.fail())
		cout << "plaintext.txt does not exist";
	
	else
	{

		buffer << in.rdbuf();
		std::string contents(buffer.str());
		contents2 = contents;

	}
	
	
	in.close();

	//encrypt//
	ofstream fileencrypted ("ENCRYPTED.txt");


	
	string concat;
	
	//p1//

	for (int a=0;a<contents2.length();a++)
	{
		
		
		int charval = contents2[a];
		stringstream out;
		out << charval;
		string temp = out.str();

		if (charval <10)
			temp.insert (0,"00");

		else if (charval <100)
			temp.insert (0,"0");

		concat +=temp;

	
		
	} 

	

	//p2//
	int Lclear = PKn.length()-1;
	
	for (int a=0;a<concat.length() ;a = a+ Lclear)
	{


		string tempsplit =concat.substr (a,Lclear);
			
		
		mpz_t partcrypt;
		mpz_init_set_str(partcrypt,tempsplit.c_str(),10);
		mpz_powm (partcrypt,partcrypt,PKe1,PKn1);

		//p3//
			char test[150000];
			mpz_get_str(test,10,partcrypt);
			string test4 (test);	
			int zab = test4.length();

			for (int q =0;q < (PKn.length()- zab);q++)
				test4.insert (0,"0");
		
		
		encryptfile << test4;
		test4.clear();
		tempsplit.clear();

	}	

	
	
	break;
	}
	
	


I know this switch statement is executing due to ofstream activity.
Last edited on
There's a lot of IO activity and stuff I cannot reproduce at my PC and therefore your code to reproduce is no good. I am therefore unable to help you debug this code to determine the reason of the failure because I just don't have the pieces needed.

The best I can do with that is ask you: Which line of code is failing in the above? Maybe I can spot an issue.
Topic archived. No new replies allowed.