POST http:// localhost:3000/404(未找到)(已更新)(POST http://localhost:3000/ 404 (Not Found))
我正在使用带上传功能的网络文件浏览器。 我正在使用Angular File Upload指令和angular web文件浏览器 。
首先,我已经下载了文件Web浏览器并对其进行了配置。
其次,我已经下载了文件上传指令,并且一步一步完成所有操作,我的页面完美无缺
但是当我试图上传我正在收集的东西时
FileUploader.js:479 POST http:// localhost: 3000/404(未找到)
据我所知FileUploader.js找不到upload.php文件,但是我把它放到了根文件夹并提供了路径:
var uploader = $scope.uploader = new FileUploader({ url: 'upload.php' });
这是它的样子:
角/ app.js:
(function() { 'use strict'; window.app = angular.module('fileBrowserApp', ['ngRoute', 'jsTree.directive', 'angularFileUpload']). config(['$routeProvider', function($routeProvider) { $routeProvider. when('/', { templateUrl: '../partials/home.html', controller: 'HomeCtrl' }). otherwise({ redirectTo: '/home' }); } ]); window.app.directive('attachable', function(FileUploader) { return { restrict: 'E', replace: true, templateUrl:'../partials/upload.html', link: function(scope, element, attrs) { scope.uploader = new FileUploader(); } } }) ; }());
服务器/ app.js
(function() { 'use strict'; var express = require('express'); var path = require('path'); var logger = require('morgan'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); var fs = require('fs-extra'); var routes = require('./routes.js'); var app = express(); // view engine setup app.set('views', path.join(__dirname, 'views')); app.engine('html', require('ejs').renderFile); app.set('view engine', 'html'); app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); app.use(cookieParser()); app.use(express.static(path.join(__dirname, '../client'))); app.use('/', routes); app.set('port', process.env.PORT || 3000); var server = app.listen(app.get('port'), function() { console.log('Express server listening on port ' + server.address().port); }); module.exports = app; }());
角/ controller.js
(function() { 'use strict'; app.controller('HomeCtrl', ['$scope', 'FetchFileFactory', 'FileUploader', function($scope, FetchFileFactory, FileUploader, $upload) { // ****** file upload ******* var uploader = $scope.uploader = new FileUploader({ url: '/upload', success: function (fileItem) { $scope.alerts.push({ type: 'success', msg: '"' + fileItem.file.name + '" uploaded' }); }, error: function (fileItem) { $scope.alerts.push({ type: 'danger', msg: '"' + fileItem.file.name + '" failed' }); } }); // FILTERS uploader.filters.push({ name: 'customFilter', fn: function(item /*{File|FileLikeObject}*/, options) { return this.queue.length < 10; } }); // CALLBACKS uploader.onWhenAddingFileFailed = function(item /*{File|FileLikeObject}*/, filter, options) { console.info('onWhenAddingFileFailed', item, filter, options); }; uploader.onAfterAddingFile = function(fileItem) { console.info('onAfterAddingFile', fileItem); }; uploader.onAfterAddingAll = function(addedFileItems) { console.info('onAfterAddingAll', addedFileItems); }; uploader.onBeforeUploadItem = function(item) { console.info('onBeforeUploadItem', item); }; uploader.onProgressItem = function(fileItem, progress) { console.info('onProgressItem', fileItem, progress); }; uploader.onProgressAll = function(progress) { console.info('onProgressAll', progress); }; uploader.onSuccessItem = function(fileItem, response, status, headers) { console.info('onSuccessItem', fileItem, response, status, headers); }; uploader.onErrorItem = function(fileItem, response, status, headers) { console.info('onErrorItem', fileItem, response, status, headers); }; uploader.onCancelItem = function(fileItem, response, status, headers) { console.info('onCancelItem', fileItem, response, status, headers); }; uploader.onCompleteItem = function(fileItem, response, status, headers) { console.info('onCompleteItem', fileItem, response, status, headers); }; uploader.onCompleteAll = function() { console.info('onCompleteAll'); }; console.info('uploader', uploader); // ****** file browser ******* $scope.fileViewer = 'Please select a file to view its contents'; $scope.tree_core = { multiple: false, // disable multiple node selection check_callback: function (operation, node, node_parent, node_position, more) { // operation can be 'create_node', 'rename_node', 'delete_node', 'move_node' or 'copy_node' // in case of 'rename_node' node_position is filled with the new node name if (operation === 'move_node') { return false; // disallow all dnd operations } return true; // allow all other operations } }; $scope.nodeSelected = function(e, data) { var _l = data.node.li_attr; if (_l.isLeaf) { FetchFileFactory.fetchFile(_l.base).then(function(data) { var _d = data.data; if (typeof _d == 'object') { //http://stackoverflow.com/a/7220510/1015046// _d = JSON.stringify(_d, undefined, 2); } $scope.fileViewer = _d; }); } else { //http://jimhoskins.com/2012/12/17/angularjs-and-apply.html// $scope.$apply(function() { $scope.fileViewer = 'Please select a file to view its contents'; }); } }; } ]); }());
Upload.html:
<div ng-if="uploader"> <div class="container"> <div class="row"> <div class="col-md-3"> <h3>Select files</h3> <input type="file" nv-file-select="" uploader="uploader"/> </div> <div class="col-md-9" style="margin-bottom: 40px"> <h3>Upload queue</h3> <p>Queue length: {{ uploader.queue.length }}</p> <table class="table"> <thead> <tr> <th width="50%">Name</th> <th ng-show="uploader.isHTML5">Size</th> <th ng-show="uploader.isHTML5">Progress</th> <th>Status</th> <th>Actions</th> </tr> </thead> <tbody> <tr ng-repeat="item in uploader.queue"> <td><strong>{{ item.file.name }}</strong></td> <td ng-show="uploader.isHTML5" nowrap>{{ item.file.size/1024/1024|number:2 }} MB</td> <td ng-show="uploader.isHTML5"> <div class="progress" style="margin-bottom: 0;"> <div class="progress-bar" role="progressbar" ng-style="{ 'width': item.progress + '%' }"></div> </div> </td> <td class="text-center"> <span ng-show="item.isSuccess"><i class="glyphicon glyphicon-ok"></i></span> <span ng-show="item.isCancel">&t;i class="glyphicon glyphicon-ban-circle"></i></span> <span ng-show="item.isError"><i class="glyphicon glyphicon-remove"></i></span> </td> <td nowrap> <button type="button" class="btn btn-success btn-xs" ng-click="item.upload()" ng-disabled="item.isReady || item.isUploading || item.isSuccess"> <span class="glyphicon glyphicon-upload"></span> Upload </button> <button type="button" class="btn btn-warning btn-xs" ng-click="item.cancel()" ng-disabled="!item.isUploading"> <span class="glyphicon glyphicon-ban-circle"></span> Cancel </button> <button type="button" class="btn btn-danger btn-xs" ng-click="item.remove()"> <span class="glyphicon glyphicon-trash"></span> Remove </button> </td> </tr> </tbody> </table> <div> <div> Queue progress: <div class="progress" style=""> <div class="progress-bar" role="progressbar" ng-style="{ 'width': uploader.progress + '%' }"></div> </div> </div> <!--<button type="button" class="btn btn-success btn-s" ng-click="uploader.uploadAll()" ng-disabled="!uploader.getNotUploadedItems().length">--> <!--<span class="glyphicon glyphicon-upload"></span> Upload all--> <!--</button>--> <!--<button type="button" class="btn btn-warning btn-s" ng-click="uploader.cancelAll()" ng-disabled="!uploader.isUploading">--> <!--<span class="glyphicon glyphicon-ban-circle"></span> Cancel all--> <!--</button>--> <!--<button type="button" class="btn btn-danger btn-s" ng-click="uploader.clearQueue()" ng-disabled="!uploader.queue.length">--> <!--<span class="glyphicon glyphicon-trash"></span> Remove all--> <!--</button>--> </div> </div> </div> </div> </div>
route.js
(function() { 'use strict'; var express = require('express'); var router = express.Router(); var fs = require('fs'); var path = require('path'); /* GET home page. */ router.get('/', function(req, res) { res.render('index'); }); /* Serve the Tree */ router.get('/api/tree', function(req, res) { var _p; if (req.query.id == 1) { _p = path.resolve(__dirname, '..', 'node_modules'); processReq(_p, res); } else { if (req.query.id) { _p = req.query.id; processReq(_p, res); } else { res.json(['No valid data found']); } } }); /* Serve a Resource */ router.get('/api/resource', function(req, res) { res.send(fs.readFileSync(req.query.resource, 'UTF-8')); }); function processReq(_p, res) { var resp = []; fs.readdir(_p, function(err, list) { for (var i = list.length - 1; i >= 0; i--) { resp.push(processNode(_p, list[i])); } res.json(resp); }); } function processNode(_p, f) { var s = fs.statSync(path.join(_p, f)); return { "id": path.join(_p, f), "text": f, "icon" : s.isDirectory() ? 'jstree-custom-folder' : 'jstree-custom-file', "state": { "opened": false, "disabled": false, "selected": false }, "li_attr": { "base": path.join(_p, f), "isLeaf": !s.isDirectory() }, "children": s.isDirectory() }; } module.exports = router; }());
我的错误在哪里? 我感谢任何帮助。
我使用这个例子并取出了我的upload.php,固定服务器/ app.js和controller.js,但仍然得到相同的错误
更新
我把这段代码放到routes.js中
var multer = require('multer'); var storage = multer.diskStorage({ destination: function (req, file, callback) { callback(null, './upload'); }, filename: function (req, file, callback) { callback(null, file.fieldname + '-' + Date.now()); } }); var upload = multer({ storage : storage}).single('test'); router.post('/',function(req,res){ upload(req,res,function(err) { if(err) { return res.end("Error uploading file."); } res.end("File is uploaded"); }); });
现在帖子返回200,但文件夹“upload”中没有任何内容。 有什么想法,现在有什么不对吗?
I'm working on web file browser with upload function. I'm using Angular File Upload directive and angular web file browser.
First off I've downloaded file web browser and configured it.
Second I've downloaded file upload directive and did everything step by step and my page works perfect
but when I'm trying to upload something I'm getting
FileUploader.js:479 POST http://localhost:3000/ 404 (Not Found)
I understand that FileUploader.js can't find upload.php file, but I put it to the root folder and provided path:
var uploader = $scope.uploader = new FileUploader({ url: 'upload.php' });
this is how it looks:
angular/app.js:
(function() { 'use strict'; window.app = angular.module('fileBrowserApp', ['ngRoute', 'jsTree.directive', 'angularFileUpload']). config(['$routeProvider', function($routeProvider) { $routeProvider. when('/', { templateUrl: '../partials/home.html', controller: 'HomeCtrl' }). otherwise({ redirectTo: '/home' }); } ]); window.app.directive('attachable', function(FileUploader) { return { restrict: 'E', replace: true, templateUrl:'../partials/upload.html', link: function(scope, element, attrs) { scope.uploader = new FileUploader(); } } }) ; }());
server/app.js
(function() { 'use strict'; var express = require('express'); var path = require('path'); var logger = require('morgan'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); var fs = require('fs-extra'); var routes = require('./routes.js'); var app = express(); // view engine setup app.set('views', path.join(__dirname, 'views')); app.engine('html', require('ejs').renderFile); app.set('view engine', 'html'); app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); app.use(cookieParser()); app.use(express.static(path.join(__dirname, '../client'))); app.use('/', routes); app.set('port', process.env.PORT || 3000); var server = app.listen(app.get('port'), function() { console.log('Express server listening on port ' + server.address().port); }); module.exports = app; }());
angular/controller.js
(function() { 'use strict'; app.controller('HomeCtrl', ['$scope', 'FetchFileFactory', 'FileUploader', function($scope, FetchFileFactory, FileUploader, $upload) { // ****** file upload ******* var uploader = $scope.uploader = new FileUploader({ url: '/upload', success: function (fileItem) { $scope.alerts.push({ type: 'success', msg: '"' + fileItem.file.name + '" uploaded' }); }, error: function (fileItem) { $scope.alerts.push({ type: 'danger', msg: '"' + fileItem.file.name + '" failed' }); } }); // FILTERS uploader.filters.push({ name: 'customFilter', fn: function(item /*{File|FileLikeObject}*/, options) { return this.queue.length < 10; } }); // CALLBACKS uploader.onWhenAddingFileFailed = function(item /*{File|FileLikeObject}*/, filter, options) { console.info('onWhenAddingFileFailed', item, filter, options); }; uploader.onAfterAddingFile = function(fileItem) { console.info('onAfterAddingFile', fileItem); }; uploader.onAfterAddingAll = function(addedFileItems) { console.info('onAfterAddingAll', addedFileItems); }; uploader.onBeforeUploadItem = function(item) { console.info('onBeforeUploadItem', item); }; uploader.onProgressItem = function(fileItem, progress) { console.info('onProgressItem', fileItem, progress); }; uploader.onProgressAll = function(progress) { console.info('onProgressAll', progress); }; uploader.onSuccessItem = function(fileItem, response, status, headers) { console.info('onSuccessItem', fileItem, response, status, headers); }; uploader.onErrorItem = function(fileItem, response, status, headers) { console.info('onErrorItem', fileItem, response, status, headers); }; uploader.onCancelItem = function(fileItem, response, status, headers) { console.info('onCancelItem', fileItem, response, status, headers); }; uploader.onCompleteItem = function(fileItem, response, status, headers) { console.info('onCompleteItem', fileItem, response, status, headers); }; uploader.onCompleteAll = function() { console.info('onCompleteAll'); }; console.info('uploader', uploader); // ****** file browser ******* $scope.fileViewer = 'Please select a file to view its contents'; $scope.tree_core = { multiple: false, // disable multiple node selection check_callback: function (operation, node, node_parent, node_position, more) { // operation can be 'create_node', 'rename_node', 'delete_node', 'move_node' or 'copy_node' // in case of 'rename_node' node_position is filled with the new node name if (operation === 'move_node') { return false; // disallow all dnd operations } return true; // allow all other operations } }; $scope.nodeSelected = function(e, data) { var _l = data.node.li_attr; if (_l.isLeaf) { FetchFileFactory.fetchFile(_l.base).then(function(data) { var _d = data.data; if (typeof _d == 'object') { //http://stackoverflow.com/a/7220510/1015046// _d = JSON.stringify(_d, undefined, 2); } $scope.fileViewer = _d; }); } else { //http://jimhoskins.com/2012/12/17/angularjs-and-apply.html// $scope.$apply(function() { $scope.fileViewer = 'Please select a file to view its contents'; }); } }; } ]); }());
Upload.html:
<div ng-if="uploader"> <div class="container"> <div class="row"> <div class="col-md-3"> <h3>Select files</h3> <input type="file" nv-file-select="" uploader="uploader"/> </div> <div class="col-md-9" style="margin-bottom: 40px"> <h3>Upload queue</h3> <p>Queue length: {{ uploader.queue.length }}</p> <table class="table"> <thead> <tr> <th width="50%">Name</th> <th ng-show="uploader.isHTML5">Size</th> <th ng-show="uploader.isHTML5">Progress</th> <th>Status</th> <th>Actions</th> </tr> </thead> <tbody> <tr ng-repeat="item in uploader.queue"> <td><strong>{{ item.file.name }}</strong></td> <td ng-show="uploader.isHTML5" nowrap>{{ item.file.size/1024/1024|number:2 }} MB</td> <td ng-show="uploader.isHTML5"> <div class="progress" style="margin-bottom: 0;"> <div class="progress-bar" role="progressbar" ng-style="{ 'width': item.progress + '%' }"></div> </div> </td> <td class="text-center"> <span ng-show="item.isSuccess"><i class="glyphicon glyphicon-ok"></i></span> <span ng-show="item.isCancel"><i class="glyphicon glyphicon-ban-circle"></i></span> <span ng-show="item.isError"><i class="glyphicon glyphicon-remove"></i></span> </td> <td nowrap> <button type="button" class="btn btn-success btn-xs" ng-click="item.upload()" ng-disabled="item.isReady || item.isUploading || item.isSuccess"> <span class="glyphicon glyphicon-upload"></span> Upload </button> <button type="button" class="btn btn-warning btn-xs" ng-click="item.cancel()" ng-disabled="!item.isUploading"> <span class="glyphicon glyphicon-ban-circle"></span> Cancel </button> <button type="button" class="btn btn-danger btn-xs" ng-click="item.remove()"> <span class="glyphicon glyphicon-trash"></span> Remove </button> </td> </tr> </tbody> </table> <div> <div> Queue progress: <div class="progress" style=""> <div class="progress-bar" role="progressbar" ng-style="{ 'width': uploader.progress + '%' }"></div> </div> </div> <!--<button type="button" class="btn btn-success btn-s" ng-click="uploader.uploadAll()" ng-disabled="!uploader.getNotUploadedItems().length">--> <!--<span class="glyphicon glyphicon-upload"></span> Upload all--> <!--</button>--> <!--<button type="button" class="btn btn-warning btn-s" ng-click="uploader.cancelAll()" ng-disabled="!uploader.isUploading">--> <!--<span class="glyphicon glyphicon-ban-circle"></span> Cancel all--> <!--</button>--> <!--<button type="button" class="btn btn-danger btn-s" ng-click="uploader.clearQueue()" ng-disabled="!uploader.queue.length">--> <!--<span class="glyphicon glyphicon-trash"></span> Remove all--> <!--</button>--> </div> </div> </div> </div> </div>
route.js
(function() { 'use strict'; var express = require('express'); var router = express.Router(); var fs = require('fs'); var path = require('path'); /* GET home page. */ router.get('/', function(req, res) { res.render('index'); }); /* Serve the Tree */ router.get('/api/tree', function(req, res) { var _p; if (req.query.id == 1) { _p = path.resolve(__dirname, '..', 'node_modules'); processReq(_p, res); } else { if (req.query.id) { _p = req.query.id; processReq(_p, res); } else { res.json(['No valid data found']); } } }); /* Serve a Resource */ router.get('/api/resource', function(req, res) { res.send(fs.readFileSync(req.query.resource, 'UTF-8')); }); function processReq(_p, res) { var resp = []; fs.readdir(_p, function(err, list) { for (var i = list.length - 1; i >= 0; i--) { resp.push(processNode(_p, list[i])); } res.json(resp); }); } function processNode(_p, f) { var s = fs.statSync(path.join(_p, f)); return { "id": path.join(_p, f), "text": f, "icon" : s.isDirectory() ? 'jstree-custom-folder' : 'jstree-custom-file', "state": { "opened": false, "disabled": false, "selected": false }, "li_attr": { "base": path.join(_p, f), "isLeaf": !s.isDirectory() }, "children": s.isDirectory() }; } module.exports = router; }());
Where is my mistake? I appreciate any help.
I used this example and take out my upload.php at all, fixed server/app.j s and controller.js , but still getting same error
Updated
I put this code into routes.js
var multer = require('multer'); var storage = multer.diskStorage({ destination: function (req, file, callback) { callback(null, './upload'); }, filename: function (req, file, callback) { callback(null, file.fieldname + '-' + Date.now()); } }); var upload = multer({ storage : storage}).single('test'); router.post('/',function(req,res){ upload(req,res,function(err) { if(err) { return res.end("Error uploading file."); } res.end("File is uploaded"); }); });
Now post returns 200, but nothing appears in folder "upload". Are there any ideas, what's wrong now?
原文:https://stackoverflow.com/questions/36627337
最满意答案
使用
awk
你可以这样做:awk '/00-1E-B8-05-7C-74/ {$0=$0":p=abcde"} 1' file 00-1E-B8-05-7C-74:p=abcde
它将在
00-1E-B8-05-7C-74
行之后添加:p=abcde
更新:
awk '$0~m {$0=$0":p=abcde"} 1' m=$(cat mac.txt) file
With
awk
you can do this:awk '/00-1E-B8-05-7C-74/ {$0=$0":p=abcde"} 1' file 00-1E-B8-05-7C-74:p=abcde
It will add
:p=abcde
after lines with00-1E-B8-05-7C-74
Update:
awk '$0~m {$0=$0":p=abcde"} 1' m=$(cat mac.txt) file
相关问答
更多-
您可以使用以下内容: T(R(U(N(C(A(T(ED?)?)?)?)?)?)?)? 码: corrected = re.sub(r" (T(R(U(N(C(A(T(ED?)?)?)?)?)?)?)?)$", "", original) You can use the following: T(R(U(N(C(A(T(ED?)?)?)?)?)?)?)? code: corrected = re.sub(r" (T(R(U(N(C(A(T(ED?)?)?)?)?)?)?)?)$", "", orig ...
-
这个答案对于你正在寻找的东西来说可能过于简单,但至少应该让你开始朝着正确的方向前进。 set yourText to "This is some test text that you might want to work with." set i to offset of "test" in yourText set finalText to characters i thru -1 of yourText as string 作为旁注,我看到很多人在不需要的时候在像TextEdit这样的应用程序中做事。 ...
-
下面的代码对我有用! 为了获得所需的JSON,我首先必须遍历树层次结构。 这意味着打开“特征”,“几何”,最后打开“坐标”以获得坐标。 最后添加Linestring和括号以再次转换为适当的JSON文件。 // look for features if (jsoninput.contains("features")) { jsonArray1 = obj.getJSONArray("features"); System.out.println(jsonArray ...
-
您的程序可以简化如下: # read the file into a list of lines with open('data.csv','r') as f: lines = f.read().split("\n") print("Number of lines is {}".format(len(lines))) word = 'someword' # dummy word. you take it from input # iterate over lines, and print o ...
-
你可以用awk做到这一点: awk '{if ((NR-1) % 5) {print $0} else {print $0 " >>"}}' 我们检查行号减去1是5的倍数,如果是,我们输出行后跟>> ,否则,我们只输出行。 注意 :上面的代码每5行输出一次后缀,因为这是您的示例工作所需的内容。 You can do it with awk: awk '{if ((NR-1) % 5) {print $0} else {print $0 " >>"}}' We check if line number m ...
-
用特定单词略读(Skip line with specific word)[2021-10-01]
如果你想逐行删除不需要的行来应用一些逻辑,那么逐行读取文件或者在内存中读取它们之后处理一行(选择取决于文件大小) 这种方法使用IEnumerable扩展,在ReadLines返回的行上(返回行的IEnumerable并且不将它们全部加载到内存中)。 For Each f In dinfo.GetFiles("*.txt", SearchOption.AllDirectories) Dim lines = File.ReadLines(f.FullName). Wher ... -
在行尾添加特定单词(Add a specific word to end of line)[2023-10-16]
使用awk你可以这样做: awk '/00-1E-B8-05-7C-74/ {$0=$0":p=abcde"} 1' file 00-1E-B8-05-7C-74:p=abcde 它将在00-1E-B8-05-7C-74行之后添加:p=abcde 更新: awk '$0~m {$0=$0":p=abcde"} 1' m=$(cat mac.txt) file With awk you can do this: awk '/00-1E-B8-05-7C-74/ {$0=$0":p=abcde"} 1' f ... -
我的第一个想法是表的结构非常均匀,因此您可以使用列和行来确定特定分数的位置。 因为名称是唯一具有可变长度的元素(假设分数不超过9,因为这将给出2个字符),我将首先读取每一行的第一个单词并将其输入到一个名称数组中。 从中您可以使用行索引和列索引查找特定元素。 如果C ++不包含基于行和列索引获取字符的函数,我将遍历文件并将每个字符添加到二维数组中的相应位置。 例如: characters[0][0] 将从“名称”的开头返回N. 当然,要检索得分,您需要使用特定行的名称长度来获取值: characters[n ...
-
这个正则表达式会做到这一点! (?<=(^|\s))@([a-zA-Z0-9]{1}\w*[a-zA-Z0-9]|[a-zA-Z0-9]{1})(?=(\s|$)) 它也匹配单个字母 This Regex will do it! (?<=(^|\s))@([a-zA-Z0-9]{1}\w*[a-zA-Z0-9]|[a-zA-Z0-9]{1})(?=(\s|$)) It also matches single letter
-
如何过滤/删除行中不存在特定单词的行?(How can i filter/remove a line that a specific word is not exist in the line?)[2022-05-09]
当您按索引迭代列表并从该列表中删除项目时,您需要在每次删除项目时调整索引。 例如,如果您有包含10个项目的列表,并且您在索引3处删除了一个项目,则列表的索引和长度已更改。 该列表现在将具有.Count = 9而不是10,而索引4处的内容现在位于索引3处,索引5处的内容现在处于4,依此类推。 您还可以利用linq查找行中单词与您要搜索的单词之间的交叉点。 下面的代码应该做你想要的。 注意:将行解析为单词数组很弱,仅用于说明目的。 如果你在包含字符“hello?”的行中,则此代码不会找到匹配项。 string[ ...