[C++] Can't get the thing to insert a space char ?[C++] Can't get the thing to insert a space char ?

🏚️

Halfway House

Week 26, 2026

#include "allheaders.hpp" #include "main.hpp" using namespace std; //------------------------------------challenge specific variables and functions char GetASCIIvalue(char a, char b); vector challenge26; //------------------------------------------------------------------------------ int main(int argc, char* argv[]) { try { ifstream infile("chfile.txt"); if(!infile) { cerr << "Error opening file.\n"; return 1; } char ch; while(infile.get(ch)) { challenge26.push_back(ch); } infile.close(); int sz = challenge26.size(); string str; for(int i = 0; i < sz; i++) { if( challenge26[i] != '\n') { char a = challenge26[i]; char b = challenge26[i+1]; str += GetASCIIvalue(a,b); } } string result; for (size_t i = 0; i < str.length(); ++i) { if (i % 2 == 0) { result += str[i]; } } cout << result << endl; return(0); }// end of try catch (const runtime_error& exception) { std::cout << "Msg: " << exception.what() << "\n"; } cout << "\n"; return 0; } //---------------------------------------------------------------------------- char GetASCIIvalue(char a, char b) { char value; if( a == '\n' || b == '\n') { value = '\032'; } else { int val1 = static_cast (a); int val2 = static_cast (b); int val3 = a + b; value = static_cast (val3); } return value; }