close
Blogtrottr
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 已解決
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 已解決 
Thousands of Free eBooks

BookBub brings you free & bargain national bestselling eBooks in the genres of your choice! Sign up now & join 1.5 million happy readers.
From our sponsors
C++讀檔字串解析
Oct 2nd 2013, 17:44

我試著不用 getline() 和 split().

1. TestFile.txt
A, HELLO
B, 1
7 0,1
4 5,6,7,8,9

2. code
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <strstream>
using namespace std;

void main()
{
FILE * f;
char buffer [100];
int num;

f = fopen ("TextFile1.txt" , "r");
if (f == NULL) perror ("Error opening file");
else
{
while ( ! feof (f) )
{
if ( fgets (buffer , 100 , f) == NULL ) break;
cout << "read " << buffer;

char *p = strtok(buffer, " ,"); // ',', space
while (p)
{
if ((*p >= 'A' && *p <= 'Z') ||
(*p >= 'a' && *p <= 'z'))
{ // A-Z, a-z
cout << p << endl; // do your job
}
else if (*p >= '0' && *p <= '9')
{
strstream ss(p, strlen(p));
ss >> num;
cout << num << endl;
}
p = strtok(0, " ,");
}
}
fclose (f);
}
system("pause");
}

This entry passed through the Full-Text RSS service — if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers. Five Filters recommends:

You are receiving this email because you subscribed to this feed at blogtrottr.com.

If you no longer wish to receive these emails, you can unsubscribe from this feed, or manage all your subscriptions
全站熱搜
創作者介紹
創作者 gyynimpiamar5 的頭像
gyynimpiamar5

線上遊戲排行榜2013/2014,進擊的巨人線上看,candy crush saga外掛,正妹寫真三圍

gyynimpiamar5 發表在 痞客邦 留言(0) 人氣()