我一直在努力处理这个bug一段时间。我使用windows 10和code :: blocks 16.01 MinGW。字符不一致的回应 n
我想比较c到结束行字符。我的系统上
一个程序成功运行,只是跳过的文件的标题行:
while(c!='\n')
{
c = fgetc(traverse);
if(c == EOF)
return(1);
}
其中横向使用
fopen("traverse.dat", "r");
然而
开了,我的其他程序:
FILE * infile;
/* Open a large CSV */
infile = fopen("Getty_Megatem.csv", "r");
if(infile == NULL)
{
printf("no file");
return(EXIT_FAILURE);
}
char c = 0;
int i = 0;
/* Opens file successfully */
printf("File opened\n");
/* Count commas in first line */
while(c != '\n');
{
c = fgetc(infile);
if(c == ',')
i++;
if(c == EOF)
return(EXIT_FAILURE);
}
printf("Number of commas: %i\n", i);
fclose(infile);
return(EXIT_SUCCESS);
and
ifstream infile;
char c;
string mystr;
infile.open("ostring.dat");
// Skip a line
while (c!= '\n')
infile >> c;
getline(infile, mystr);
和(一个我真的想工作)
ifstream emdata;
string firstline;
char c = 0;
int i = 0;
vector<double> vdata;
// redundancy
vdata.reserve(10000);
// There are ~ 300 doubles per line
emdata.open("Getty_Megatem.csv");
// Skip first line
getline(emdata, firstline);
while(c != '\n' && c != EOF)
{
emdata >> vdata[i] >> c;
cout << vdata[i] << ",";
i++;
if(i == 999)
{
cout << "\n\ni>9999";
break;
}
}
emdata.close();
return 0;
是不成功的,他们编译和执行,然后永远地读取流 - 或者直到我最大迭代9999为止。所有这些文件都包含新行。
的投入,我不明白为什么你不只是'函数getline()'每行? –
我想将行读入双向量 – Edward
您的C变体有这样一行:'while(c!='\ n');'末尾有一个分号,它被解释为空语句。实际上,这说:“c'不是一个换行符,这将永远是真的。删除该分号。 –