读取行:
bestgood
int i=0;
vector<int> itime;
int c;
fp=fopen("./time.dat","r");
fscanf(fp,"%d",&c);
while(!feof(fp))
{
itime.push_back(c);
fscanf(fp,"%d",&c);
// i++;
}
fclose(fp); //这儿获取的数字最准确 获取时间列表的时间 自己加 Qtime类的时间
// printf("%d\n",itime.size()); //调试
for(int i=0;i<itime.size();i++)
printf("%d\n", itime[i]);
// QTime n(0, 0, 0); // n = 00:00:00
//QTime t1;
MainWindow w1;
// for(int i=0;i<itime.size();i++)
// {
// t1 = n.addSecs(itime[i]);
// timeClicked(t1);
// }
// //qDebug() << t.toString("hh:mm:ss"); //t = 00:01:10
// char* itime2[65535]={"0"};
vector<char*> itime1;
vector<string> itime2;
// char* c1;
// fp1=fopen("./name.dat","r");
string c1;//temp用来将所有的内容存入,用来存储“12345678910”的
ifstream fp1("./name.dat", ios::in);
// string str;
getline(fp1, c1);
itime2.push_back(c1);
while (getline(fp1, c1))//按行读文件
{
cout << endl;
itime2.push_back(c1);
cout<<itime2[1]<<endl;
}
fp1.close( );
// //fscanf(fp1,"%s\r\n",c1);
// // fgets(c1,22,fp1);
getline(fp1, c1);//按行读文件
// //cout << str << endl;//这
// string str;
// str=c1;
// itime1.push_back(c1);
// itime2.push_back(str);
// // itime2[i++]=c1;
// while(!feof(fp1))
// // for(int j=0;j<i;j++)
// {
// // itime2[i++]=c1;
// itime1.push_back(c1);
// itime2.push_back(str);
// // printf("%s\n",itime1[1]);
cout<<itime2[1];
// getline(fp1, c1);//按行读文件
// // fscanf(fp1,"%s\r\n",c1);
// // fgets(c1,22,fp1);
// // printf("%s\n",itime1[2]);
// }
//fclose(fp1); //这儿获取的数字最准确 获取时间列表的时间 自己加 Qtime类的时间
QTime n(0, 0, 0); // n = 00:00:00
QTime t1;
//MainWindow w1;
QString t2;
for(int j=0;j<itime.size();j++)
{ //printf("%s\n",itime1[i]);
printf("%s\n",itime2[j].c_str());
t1 = n.addSecs(itime[j]);
QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8")); //保证写出的文字显示不乱码 编码格式的转化
//用GBK编的码就用gbk来解码白框里显示名字
t2= QString(tr(itime2[j].c_str())); //char 转
QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK")); //弹出的对话框中显示的文字
timeClicked(t1,t2);
}
http://bbs.csdn.net/topics/300028969
string temp;//temp用来将所有的内容存入,用来存储“12345678910”的
ifstream test("test.txt", ios::in);
string str;
while (getline(test, str))//按行读文件
{
cout << str << endl;//这里可以不要,只是用来看你自己txt文档中原来的内容
if (str[0] == '>')
continue;
else
temp.insert(temp.length(),str,0,str.size());//最终都存入temp中
}
//注意 h用完后必须付回初始值:h=0
void MainWindow:: loadtime1(){//int i=0;
vector<int> itime;int c;int g=0;int h=0;int nn=0;int ca[65535]={0};vector<string> itime3;// char* c1;// fp1=fopen("./name.dat","r");string c2;//temp用来将所有的内容存入,用来存储“12345678910”的ifstream fp( "./time.dat" );// cout << ch;// fin.close();// ifstream fp("./time.dat", ios::in);// string str;// getline(fp, c2);// itime3=c2;
// char* strc;
// strc=(char*)itime3.c_str();
// char * split = ":";
// char * p;
// p = strtok (strc,split);
// while(p!=NULL) {
// // printf ("%s\n",p);
// ca[h++]=atoi(p);
// p = strtok(NULL,split);
// }
// c=ca[0]*3600+ca[1]*60+ca[2];
// itime.push_back(c);
// cout << endl;
// while (getline(fp, c2))//按行读文件
while( getline(fp,c2) ){
itime3.push_back(c2);
printf("%s\n", itime3[g].c_str());char* strc;strc=(char*)itime3[g++].c_str();char * split = ":";char * p;p = strtok (strc,split);while(p!=NULL) {// printf ("%s\n",p);ca[h++]=atoi(p);
p = strtok(NULL,split);}
h=0;c=ca[0]*3600+ca[1]*60+ca[2];itime.push_back(c);
printf("%d\n",itime[nn++]);// cout<<itime3[1]<<endl;}
fp.close( );// fp=fopen("./time.dat","r");// fscanf(fp,"%s", strc);// while(!feof(fp))
// {
// itime.push_back(c);// fscanf(fp,"%d",&c);// i++;// }// fclose(fp); //这儿获取的数字最准确 获取时间列表的时间 自己加 Qtime类的时间// printf("%d\n",itime.size()); //调试
for(int i=0;i<itime.size();i++)
printf("%d\n", itime[i]);
// QTime n(0, 0, 0); // n = 00:00:00
//QTime t1;
MainWindow w1;
// for(int i=0;i<itime.size();i++)
// {
// t1 = n.addSecs(itime[i]);
// timeClicked(t1);
// }
// //qDebug() << t.toString("hh:mm:ss"); //t = 00:01:10
// char* itime2[65535]={"0"};vector<char*> itime1;vector<string> itime2;// char* c1;// fp1=fopen("./name.dat","r");string c1;//temp用来将所有的内容存入,用来存储“12345678910”的ifstream fp1("./name.dat", ios::in);// string str;getline(fp1, c1);itime2.push_back(c1);
while (getline(fp1, c1))//按行读文件{
cout << endl;itime2.push_back(c1);
cout<<itime2[1]<<endl;}
fp1.close( );
// //fscanf(fp1,"%s\r\n",c1);
// // fgets(c1,22,fp1);
getline(fp1, c1);//按行读文件
// //cout << str << endl;//这
// string str;
// str=c1;
// itime1.push_back(c1);
// itime2.push_back(str);
// // itime2[i++]=c1;
// while(!feof(fp1))
// // for(int j=0;j<i;j++)
// {
// // itime2[i++]=c1;
// itime1.push_back(c1);
// itime2.push_back(str);
// // printf("%s\n",itime1[1]);
cout<<itime2[1];
// getline(fp1, c1);//按行读文件
// // fscanf(fp1,"%s\r\n",c1);
// // fgets(c1,22,fp1);
// // printf("%s\n",itime1[2]);
// }
//fclose(fp1); //这儿获取的数字最准确 获取时间列表的时间 自己加 Qtime类的时间QTime n(0, 0, 0); // n = 00:00:00QTime t1;//MainWindow w1;QString t2;for(int j=0;j<itime.size();j++){ //printf("%s\n",itime1[i]);printf("%s\n",itime2[j].c_str());t1 = n.addSecs(itime[j]);QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8")); //保证写出的文字显示不乱码 编码格式的转化//用GBK编的码就用gbk来解码白框里显示名字t2= QString(tr(itime2[j].c_str())); //char 转QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK")); //弹出的对话框中显示的文字timeClicked(t1,t2);
}
}文件中的:1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
输出到数组里
#include<stdio.h> int main() { int a[3][5]; int i, j; FILE * fp = fopen("C:\\Users\\Admin\\Desktop\\bin\\data.txt", "r"); if (fp == NULL) { printf("无文件"); return -1; } for (i = 0; i < 3; i++) { for (j = 0; j < 5;j++) fscanf(fp, "%d", &a[i][j]); //会自动检查有无字符 然后智能读入 //fscanf(fp, "\n"); } fclose(fp); for (i = 0; i < 3; i++) { for (j = 0; j < 5; j++) printf("%d ", a[i][j]); printf("\n"); } return 0; }#include<iostream> #include<fstream> using namespace std; #include <stdio.h> int main() { int x[5], y[5]; int i; FILE *fp; fp = fopen("C:\\Users\\Admin\\Desktop\\bin\\data.txt", "r"); for (i = 0; i<5; i++) fscanf(fp, "%d", &x[i]); for (i = 0; i<5; i++) fscanf(fp, "%d", &y[i]); fclose(fp); for (i = 0; i<5; i++) cout << x[i] << " "; cout << endl; for (i = 0; i<5; i++) cout << y[i] << " "; cout << endl; return 0; }https://zhidao.baidu.com/question/2203681855449325588.html?skiptype=2&qq-pf-to=pcqq.group1 2 3 4 5 12 53 65 45 85 请按任意键继续. . .
http://zhidao.baidu.com/link?url=vvBNJpKlv9nYVMkilYJO1hyQL-RLKxX2RZN66Q8b8JHPVpHaRbeXzq04JyRnLAmfuebyYiVdC27sMrV-JcjbkYIL32XW8AWZdX6k5D9jiUe
http://tieba.baidu.com/p/3765290807
https://zhidao.baidu.com/question/1445794127646095740.html?skiptype=2