c++ - Wrong use of fprintf? Getting exception First-chance exception -
i'm getting "first-chance exception @ 0x708a6b2e (msvcr120.dll)" in first line of print_bit_vector() in second execution. can tell why?
code:
void print_bit_vector(file* pfile, std::string title, std::vector<bool> bitvector) { fprintf(pfile, "%s:\r\n", title); int size = bitvector.size(); int = 0; (i = 0; < size; i++) { std::cout << << std::endl; //for (bool bit : bitvector) fprintf(pfile, "%d", bitvector.at(i)); } fprintf(pfile, "\r\n"); } void test() { file * pfile; pfile = fopen("c:\\...\\myfile.txt", "w"); bc bc("c:\\...\\example_test.txt"); std::vector<bool> key = std::vector<bool>(128, 0); std::vector<bool> input = std::vector<bool>(128, 1); print_bit_vector(pfile, "key", key); print_bit_vector(pfile, "input", input); //exception inside execution of print_bit_vector(...) bc.setinputsbyparty(1, key); bc.setinputsbyparty(2, input); std::vector<bool> outputs; bc.compute(outputs); print_bit_vector(pfile, "output", outputs); fclose(pfile); }
simply because %s
in printf wants char const *
, not std::string
.
you can use title.c_str()
char const *
c++ string.
Comments
Post a Comment