O
olson_ord
Hi,
I am not so new to C++, but I have not used it much. I was trying to
append a string at the end of a previous string. If I just do this in a
test program that is 3 lines long i.e. define the two strings and
append one to the other this works. However in my actual program I
cannot get this to work.
A shorter version of my code where I still cannot get the appending to
work is as follows.
--------------------- main.cpp --------------------------
#include<iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string iscas_file_name = "c17.bench";
ifstream iscas_file (iscas_file_name.c_str());
if(!iscas_file)
{
cout<< endl << "Error opening the file: " << iscas_file_name<<
" for loading.";
}
string line;
while (getline(iscas_file,line,'\n'))
{
string temp = "** ";
line.append(temp);
cout<<line<<endl;
}
return 0;
}
-------------------- End of main.cpp ---------------------------
-------------------------- c17.bench ---------------------------
# c17
# 5 inputs
# 2 outputs
# 0 inverter
# 6 gates ( 6 NANDs )
----------------End of c17.bench ------------------------
--------- Output Obtained ----------------
** 17
** inputs
** outputs
** inverter
** gates ( 6 NANDs )
--------- End of Output Obtained ----------------
If I pipe this output to a file - I receive the correct output -
but if I 'cout' on the terminal its wrong. (I am using
'Konsole' on KDE.) So what am I doing wrong?
I am sorry if this question is obvious - but its new to me.
Thanks a lot.
O.O.
I am not so new to C++, but I have not used it much. I was trying to
append a string at the end of a previous string. If I just do this in a
test program that is 3 lines long i.e. define the two strings and
append one to the other this works. However in my actual program I
cannot get this to work.
A shorter version of my code where I still cannot get the appending to
work is as follows.
--------------------- main.cpp --------------------------
#include<iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string iscas_file_name = "c17.bench";
ifstream iscas_file (iscas_file_name.c_str());
if(!iscas_file)
{
cout<< endl << "Error opening the file: " << iscas_file_name<<
" for loading.";
}
string line;
while (getline(iscas_file,line,'\n'))
{
string temp = "** ";
line.append(temp);
cout<<line<<endl;
}
return 0;
}
-------------------- End of main.cpp ---------------------------
-------------------------- c17.bench ---------------------------
# c17
# 5 inputs
# 2 outputs
# 0 inverter
# 6 gates ( 6 NANDs )
----------------End of c17.bench ------------------------
--------- Output Obtained ----------------
** 17
** inputs
** outputs
** inverter
** gates ( 6 NANDs )
--------- End of Output Obtained ----------------
If I pipe this output to a file - I receive the correct output -
but if I 'cout' on the terminal its wrong. (I am using
'Konsole' on KDE.) So what am I doing wrong?
I am sorry if this question is obvious - but its new to me.
Thanks a lot.
O.O.