我正在寻找一个 C/C++ 甚至 C# 代码来修剪文本文件中每一行的第一个单词
例如文件.txt
test C:\Windows\System32\cacl.exe
download C:\Program Files\MS\
所以我将剩下:
C:\Windows\System32\cacl.exe
C:\Program Files\MS\
我有当前的代码,但它似乎不起作用:
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
char s[2048];
while (fgets(s, sizeof(s), stdin))
{
char *pos = strpbrk(s, "|\r\n");
if (pos != 0)
fputs(pos+1, stdout);
}
return 0;
}
最佳答案
#include <iostream>
using namespace std;
int main()
{
string tmp;
while ( !cin.eof() )
{
cin >> tmp;
getline(cin, tmp);
cout << tmp << endl;
}
}
关于C++/C : Trim the first word of each line of a text file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6084027/