jixingzhong(瞌睡虫·星辰)老大在不在啊解决办法
jixingzhong(瞌睡虫·星辰)老大在不在啊,急
jixingzhong(瞌睡虫·星辰)
你在之前发表的
#include <fstream>
#include <string>
#include <iostream>
using namespace std;
int main()
{
ifstream ifile( "test.txt ");// input
ofstream ofile( "output.txt ");// output
string company, address, zcode, name, tmp;
int count, i;
while (!ifile.eof())
{
getline(ifile, company); //company
getline(ifile, address); //address
address = address.substr(address.find( ": ")+2); //sub-string
getline(ifile, tmp);
if (tmp.find( "邮 ") != string::npos) // zcode
{
zcode = tmp.substr( tmp.find( ": ")+2 );
getline(ifile, tmp);
}
else // count
{
zcode = " ";
}
count = tmp[tmp.find( ": ")+2]- '0 '; //get count
ifile> > name; // name
name = name.substr( name.find( ": ")+2 );
ofile < <company < < ", " < <address < < ", " < <zcode < < ", "
< <count < < "名, " < <name < <endl;
for(i=1; i <count; i++) // the following names
{
ifile> > name;
ofile < <company < < ", " < <address < < ", " < <zcode < < ", "
< <count < < "名, " < <name < <endl;
}
getline(ifile, tmp); // the white space after names
getline(ifile, tmp); // read the division line
//continue
}
return 0;
}
里面有一句
count = tmp[tmp.find( ": ")+2]- '0 '; //get count
里面的- '0 '是什么 意思 ?
我再问问
如果我的人数超过10名的时候怎么办?
现在 我遇到的问题是只要人数超过了10名,就无法打印出来了,最多只能打印9名
------解决方案--------------------
他不在,就是在也未必有时间回答你。
我来告诉你。。
里面的- '0 '是什么 意思 ?
意思是减 48。
'0 '字符的数值是48。
没明白继续提问。
------解决方案--------------------
- '0 ' 是为了从字符转换到 数值:
1 = '1 '- '0 '
------解决方案--------------------
如果会超过10,那么这么修改:
count = tmp[tmp.find( ": ")+2]- '0 '; //get count
==》
istringtream t( tmp.substr(tmp.find( ": ")+2) );
t> > count; //get count
jixingzhong(瞌睡虫·星辰)
你在之前发表的
#include <fstream>
#include <string>
#include <iostream>
using namespace std;
int main()
{
ifstream ifile( "test.txt ");// input
ofstream ofile( "output.txt ");// output
string company, address, zcode, name, tmp;
int count, i;
while (!ifile.eof())
{
getline(ifile, company); //company
getline(ifile, address); //address
address = address.substr(address.find( ": ")+2); //sub-string
getline(ifile, tmp);
if (tmp.find( "邮 ") != string::npos) // zcode
{
zcode = tmp.substr( tmp.find( ": ")+2 );
getline(ifile, tmp);
}
else // count
{
zcode = " ";
}
count = tmp[tmp.find( ": ")+2]- '0 '; //get count
ifile> > name; // name
name = name.substr( name.find( ": ")+2 );
ofile < <company < < ", " < <address < < ", " < <zcode < < ", "
< <count < < "名, " < <name < <endl;
for(i=1; i <count; i++) // the following names
{
ifile> > name;
ofile < <company < < ", " < <address < < ", " < <zcode < < ", "
< <count < < "名, " < <name < <endl;
}
getline(ifile, tmp); // the white space after names
getline(ifile, tmp); // read the division line
//continue
}
return 0;
}
里面有一句
count = tmp[tmp.find( ": ")+2]- '0 '; //get count
里面的- '0 '是什么 意思 ?
我再问问
如果我的人数超过10名的时候怎么办?
现在 我遇到的问题是只要人数超过了10名,就无法打印出来了,最多只能打印9名
------解决方案--------------------
他不在,就是在也未必有时间回答你。
我来告诉你。。
里面的- '0 '是什么 意思 ?
意思是减 48。
'0 '字符的数值是48。
没明白继续提问。
------解决方案--------------------
- '0 ' 是为了从字符转换到 数值:
1 = '1 '- '0 '
------解决方案--------------------
如果会超过10,那么这么修改:
count = tmp[tmp.find( ": ")+2]- '0 '; //get count
==》
istringtream t( tmp.substr(tmp.find( ": ")+2) );
t> > count; //get count