|
between 5 and 6 there is an empty line;
cout << "\n";
Spaces?.. What's the problem;
cout << " ";
To tabulate;
cout << "\t";
--
======
Arman
|
|
|
|
|
<br />
#include<iostream.h><br />
#include<fstream.h><br />
#include<stdio.h><br />
#include<cstring.h><br />
<br />
void main()<br />
{<br />
int i=0;<br />
int num[66];<br />
string d_ic;<br />
<br />
ifstream infile("C:\\section17.txt");<br />
<br />
while(i<66)<br />
{<br />
infile>>num[i]>>d_ic;<br />
{<br />
if(num[i]<=13)<br />
cout<<num[i]<<"\t"<<d_ic<<"\t"<<"Group A"<<endl;<br />
<br />
cout<<endl;<br />
<br />
else<br />
cout<<num[i]<<"\t"<<d_ic<<"\t"<<"Group B"<<endl;<br />
}<br />
i++;<br />
}<br />
cout<<endl;<br />
cout<<"Hello"<<endl;<br />
<br />
<br />
getchar();<br />
<br />
}<br />
i have a name list of the following
1 123123124124
2 123123123123
3 343242342342
4 123354352525
5 234523525255
6 234523413412
7 123421341234
8 234123423412
9 343434355266
10 123421342423
11 123421561666
And the source code i have written cannot produce the required form of table.
|
|
|
|
|
Did you try gets()?
Cheers,
Suresh
|
|
|
|
|
i have did that. Can i do the same if the name is not key in by the user. Because i need to read the name directly from a name list given.
|
|
|
|
|
The code snippet you've shown here, and the problem/request in your initial post, do not even come close to matching. Explain clearly what you are after.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Well, in the code i have sent i am trying to show the following :
1 12312312312 Group A
2 12155132415 Group A
3
4
5
6
7
8 4325141235 Group B
9
10
In my initial post i am requesting for help to show the names. Since i can't do that so i am trying to at least show the identification number(I/C) and the group. Also with the spacing after number 7(in my code, after number 13. I have 66 i/c in my name list) The problem i have encountered is that after the spacing the i/c for group B cant't be shown. Why is that?
|
|
|
|
|
separate each field with a comma :
1, Tan Chin Chee, 1234456666, Exp 1, Exp 2, Exp 3, A
or put " around strings
1 "Tan Chin Chee" 1234456666 "Exp 1" "Exp 2" "Exp 3" "A"
or store your file as an xml file.
|
|
|
|
|
i have already tried various type of storing ways. I have tried to store the names as char,string,int,double,float...everything i can think of. But it just won't read the name. Weird~~
|
|
|
|
|
tanchinchee wrote: i am trying to develop a table...
In a database?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
To read the name list from a database..Yes
|
|
|
|
|
tanchinchee wrote: To read the name list from a database..Yes
Then why are you wanting to "...develop a table?" Developing a table, and reading from it, are two different things.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
o i might be misleading you. Act i am trying to read the name from a database and then cout it into a table.
|
|
|
|
|
tanchinchee wrote: Act i am trying to read the name from a database and then cout it into a table.
So does section17.txt represent the "database" that you are reading from? If so, what does it look like?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Message Closed
modified 27-Jan-22 7:04am.
|
|
|
|
|
Ok, how many columns is each row comprised of?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Well in my table there are suppose to be 5 columns. Which will look like this
Num Name I/C Group Week
Week 1 Week 2 Week 3
|
|
|
|
|
tanchinchee wrote: Well in my table there are suppose to be 5 columns.
So why the two rows?
In any case, as Maximilien has already suggested, you need a way of delimiting each column with something other than a space. Sans that, it's not possible to differentiate between a space between columns and a space within a column.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Opps sorry...plz omit the second row...
|
|
|
|
|
Hi, i have a weird problem i can't seem to find the source of the problem.
I have an edit box with a button to allow browsing for file. When i debug, i found out that under outputdata>_Fb>_Str, _Str value is 0x00000000 {???}. This causes the file unable to open. Is the problem lies in any of the functions? Can anyone help me to explain what may cause this problem? Below are the codes and any replies or advice is highly appreciated:
void MyDlg::OnBrowse()
{
OPENFILENAME openfile;
openfile.lStructSize=sizeof(OPENFILENAME) ;
openfile.hwndOwner=AfxGetApp()->m_pMainWnd->m_hWnd;
openfile.lpstrFilter="Text Files (.txt)\0*.txt\0All Files (*.*)\0*.*\0";
UpdateData();
openfile.lpstrInitialDir=m_binfile;
openfile.lpstrTitle="Specify file";
openfile.lpstrCustomFilter=NULL;
CString ext=m_binfile.Right(3);
ext.MakeUpper();
openfile.nFilterIndex=1;
CString binfile=m_binfile;
binfile=binfile.Mid(binfile.ReverseFind('\\')+1);
char file[MAX_PATH];
file[0]=0;
strcpy(file,binfile);
openfile.lpstrFile=file;
openfile.nMaxFile=MAX_PATH;
openfile.lpstrFileTitle=NULL;
openfile.Flags=OFN_HIDEREADONLY;
openfile.nFileOffset=0;
openfile.nFileExtension=0;
openfile.lpstrDefExt=ext;
openfile.lCustData=0;
if (GetOpenFileName(&openfile))
{
m_binfile=file;
UpdateData(FALSE);
OnLoad();
}
}
void CICTesterDlg::OnLoad()
{
UpdateData();
CString file;
file="abc.txt";
std::ifstream outputdata;
outputdata.open(file), ios::in);
if ( !outputdata.is_open() )
{
MessageBox(_T("Unable to open file!"),_T("WARNING"),MB_ICONEXCLAMATION);
return;
}
outputdata.close();
}
|
|
|
|
|
cyn8 wrote: When i debug, i found out that under outputdata>_Fb>_Str, _Str value is 0x00000000 {???}. This causes the file unable to open.
I don't see any code like this. What am I missing?
This is the file open code I see:
CString file;
file="abc.txt";
std::ifstream outputdata;
outputdata.open(file), ios::in);
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
_Str can be seen in the debug window. It is under the outputdata variable. Besides that, is OnBrowse function lacking of any command. The file can't open whenever the OnBrowse function is used.
|
|
|
|
|
After a successful GetOpenFileName call, what is in your "file" (openfile.lpstrFile) array?
You copy it to another variable like this:
m_binfile=file;
but your code sample trie to open a different file.
???
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
actually i modify the code pasted here as the original code is too long. The file i open in OnBrowse is different from the one in Onload. However, i think the OnBrowse function somehow affect the opening of the file in OnLoad. This is because, if i didn't clicked on OnBrowse before i clicked on Onload, the file can be open without error. But i don't understand why this is happening...please help...it's urgent..Thank you
|
|
|
|
|
cyn8 wrote: ...please help...it's urgent..
If the file open is failing then the pathname you are passing is invalid.
That's something you'll have to check in the debugger.
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I've check the path name and it is correct.Is the method use in OnBrowse affect anything in opening other files? Because when OnBrowse button has been click and the 'Open' button is clicked, other method(by selecting the file specified in a combobox) which has no problem before the browse button is clicked, is unable to open the file.
|
|
|
|