我在Windows计算机上使用Cygwin来从远程Linux计算机上获取一些信息,并将结果写入文件。这是我的命令:
ssh user@remotemachine ps -aef | grep vnc | grep -v grep | awk '{print "<size>"$11"<\/size>""\n""<colorDepth>"$13"<\/colorDepth>"}' > myfile.txt
Run Code Online (Sandbox Code Playgroud)
但是,当我然后跑步
ls -l
Run Code Online (Sandbox Code Playgroud)
在写入myfile.txt的目录上,它表明文件名实际上是myfile.txt吗? (带有问号)。多余字符来自哪里,如何获取打印代码以正确命名文件,就像myfile.txt一样
我只需要运行另一个命令,例如
mv myfile.txt? myfile.txt
Run Code Online (Sandbox Code Playgroud)
要么
mv myfile.txt^M myfile.txt
Run Code Online (Sandbox Code Playgroud)
但是在我的bash脚本中似乎都找不到要重命名的文件(尽管有趣的是,我可以从终端(不在脚本中)开始输入
mv myf
Run Code Online (Sandbox Code Playgroud)
然后使用Tab键完成对文件的查找,然后使用新的文件名结束该行,并成功重命名了该文件。
我正在尝试用SDL编译这段代码
#include <SDL.h>
int main(int argc, char * argv[]){
return 0;
}
Run Code Online (Sandbox Code Playgroud)
文件本身编译得很好
g++ -c main.cpp -ISDL/include
Run Code Online (Sandbox Code Playgroud)
但是使用g ++在cygwin中使用以下命令进行编译
g++ -o test main.o -lSDL2 -lSDL2main -L SDL/lib/x64
Run Code Online (Sandbox Code Playgroud)
产生这个巨大的错误......在我看来,这似乎是SDL本身的问题......
$ g++ -o test main.o -lSDL2 -lSDL2main -L SDL/lib/x64
Warning: corrupt .drectve at end of def file
SDL/lib/x64/SDL2main.lib(./x64/Release/SDL_windows_main.obj):(.text[main]+0xe): undefined reference to `SDL_SetMainReady'
SDL/lib/x64/SDL2main.lib(./x64/Release/SDL_windows_main.obj):(.text[main]+0xe): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SDL_SetMainReady'
SDL/lib/x64/SDL2main.lib(./x64/Release/SDL_windows_main.obj):(.text[WinMain]+0x29): undefined reference to `SDL_wcslen'
SDL/lib/x64/SDL2main.lib(./x64/Release/SDL_windows_main.obj):(.text[WinMain]+0x29): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SDL_wcslen'
SDL/lib/x64/SDL2main.lib(./x64/Release/SDL_windows_main.obj):(.text[WinMain]+0x46): undefined reference to `SDL_iconv_string' …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种在选择中引用单词的快速方法,比如我是从由制表符或空格字符分隔的文本块构建多个插入语句.
可以说我有
STUFF OPEN F 0 0 00:00:00-23:59:59
STUFF OPEN M 0 0 00:00:00-23:59:58
STUFF OPEN R 0 0 00:00:00-23:59:59
STUFF OPEN S 0 0 00:00:00-23:59:59
STUFF OPEN T 0 0 00:00:00-23:59:59
STUFF OPEN U 0 0 00:00:00-23:59:59
STUFF OPEN W 0 0 00:00:00-23:59:59
Run Code Online (Sandbox Code Playgroud)
我想得到
"STUFF" "OPEN" "F" "0" "0" "00:00:00-23:59:59"
"STUFF" "OPEN" "M" "0" "0" "00:00:00-23:59:58"
"STUFF" "OPEN" "R" "0" "0" "00:00:00-23:59:59"
"STUFF" "OPEN" "S" "0" "0" "00:00:00-23:59:59"
"STUFF" "OPEN" "T" "0" "0" "00:00:00-23:59:59"
"STUFF" "OPEN" "U" "0" "0" …Run Code Online (Sandbox Code Playgroud) 如何初始化std :: ofstream的向量?我正在进行套接字编程,我接收不同符号的数据.对于每个符号,我需要分配一个单独的文件句柄来向其写入数据.所以,我需要一个std :: ofstream数组.现在我想初始化其中的100个std :: ofstream.但它对我不起作用.请查看以下代码并提出替代方案.
int main(){
std::vector <std::ofstream > myFilePointerMap;
std::ofstream ofs;
ofs.open("E:\\data\\test.txt", std::ios::app);
for(int i=0;i<100;i++){
myFilePointerMap.push_back( ofs);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Windows eclipse中的cygwin gcc进行编译.
编译时出现以下错误:
'std :: ios_base&std :: ios_base :: operator =(const std :: ios_base&)'是专线789,外部位置:D:\ cygwin64\lib\gcc\x86_64-pc-cygwin\4.8.3\include\c ++\bits\ios_base.h C/C++问题
请帮我解决一下这个.
编辑: 让我解释一下我需要做什么,以便也可以支持替代解决方案.我需要创建一个侦听套接字的对象.现在,此套接字接收最多100条不同的消息,这些消息需要写入单独的文件,具体取决于各个消息中收到的id(1-100).
目前,我已经创建了一个包含文件路径的字符串向量.标题中的声明如下:
std::vector <std::string> filePathMap;
Run Code Online (Sandbox Code Playgroud)
然后我在构造函数中初始化这些文件路径,如下所示:
for(int i=0;i<100;i++){
filePathMap.push_back(" ");
}
Run Code Online (Sandbox Code Playgroud)
然后对于1到100之间的随机索引,当我订阅消息时,我将relavant文件路径设置为
filePathMap[j]=filePath;
Run Code Online (Sandbox Code Playgroud)
在收到消息后,我打开与filePathMap和index对应的文件,写入并关闭它.
最初,我想创建一个对应于这些不同符号的文件指针向量,这样当我收到一条消息时,我可以简单地写入文件指针,而不会每次都打开和关闭.因此,我在我的头文件中定义了ofstreams的向量,如下所示:
std::vector <std::ofstream > myFilePointerMap;
Run Code Online (Sandbox Code Playgroud)
但是在构造函数中,当我输入以下代码时,我得到错误:
std::ofstream ofs;
ofs.open("E:\\data\\test.txt", std::ios::app);
for(int i=0;i<100;i++){
myFilePointerMap.push_back( ofs); //THIS DOES NOT COMPILE
}
Run Code Online (Sandbox Code Playgroud)
请注意,我只是尝试将myFilePointerMap的vector初始化为100,这样当我稍后在代码中分配myFilePointerMap时,它应该可以正常工作.
myFilePointerMap[j].open(filePath.c_str(),std::ios::app);
Run Code Online (Sandbox Code Playgroud)
这里,j可以是0-99之间的任何值.
我安装了最新版本,cygwin并希望列出我的目录中的所有文件$HOME(在特殊.vimrc配置文件中).我输入ls -l并查看0个文件,但是当我尝试通过vim打开文件时,它没问题.实际上(2 TAB秒后):

怎么了?
问候Stack Overflow社区.我正在尝试从基础知识中学习C++,并遇到一些奇怪的(至少对我来说)行为.这是我的"你好世界"
#include <iostream>
int main()
{
std::cout << "Enter Thing! " << std::endl;
char Thing[]="";
std::cin >> Thing;
std::cout << "Thing is " << Thing << "!" << std::endl;
int i=0;
while (i <= 10)
{
++i;
std::cout << "Thing is " << Thing << " in " << i << " while!" << std::endl;
std::cout << "i is " << i << "!" << std::endl;
}
std::cout << "Thing is " << Thing << " after while!" << …Run Code Online (Sandbox Code Playgroud) 尝试使用fstream在C++中读取文件.但是is_open()函数总是返回0结果而readline()不会读取任何内容.请参阅下面的代码段.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string line;
ifstream myfile("D:\xx\xx\xx\xx\testdata\task1.in.1");
if (myfile.is_open()) {
while (getline(myfile, line)) {
cout << line << '\n';
}
myfile.close();
}
else
cout << "Unable to open file";
return 0;
}
Run Code Online (Sandbox Code Playgroud) 好的,所以我有,例如,
Email:Phone:Name
Email2:Phone2:Name2
Run Code Online (Sandbox Code Playgroud)
(3栏)
但是有些行只包含2列示例,
Email3:Phone3
Run Code Online (Sandbox Code Playgroud)
注意#3不包含名称/第3列
问题是如何删除仅包含2列的行.
我试图弄清楚各种头文件中的整数类型定义是如何相互关联的。
我刚刚安装了CygWin。我打开了Cygwin\x86\usr\include\machine\_default_types.h。在其中,我注意到以下代码片段:
#ifdef __INT8_TYPE__
typedef __INT8_TYPE__ __int8_t;
Run Code Online (Sandbox Code Playgroud)
根据这里,__INT8_TYPE__是预定义的预处理器宏之一。和:
您不应该直接使用这些宏。而是包括适当的标头并使用typedef。如果GCC在某些系统上未提供stdint.h标头,则可能无法在特定系统上定义其中的某些宏。
因此,似乎__INT8_TYPE__应该在其他地方定义。但是我搜索了整个CygWin安装,但没有定义。我发现的只是上面的一些条件语句。
因为我不应该直接使用它。而且没有其他文件在定义它。这个宏如何生效?还是我误会了什么?
I have a text file that is over 50GB. It contains many lines, each line is on average around 15 characters. I want each line to be unique (case sensitive). So if a line is exactly the same as another one, it must be removed, without changing the order of the other lines or sorting the file in any way.
My question is different from others because I have a huge file that cannot be handled with other solutions that …