在C++中,我有一个包含阿拉伯文本的文本文件,如:
شكلكبتعرفتقرأعربيياابنالذين
我想将这个文件的每一行解析成一个字符串并在其上使用字符串函数(如substr,length,at ...等)然后将其中的一些部分打印到输出文件中.
我试过这样做,但它打印了一些垃圾字符,如"\'c7 \'e1 \'de \'d1 \"是否有支持阿拉伯字符的库?
编辑:只需添加代码:
#include <iostream>
#include <fstream>
using namespace std;
int main(){
ifstream ip;
ip.open("d.rtf");
if(ip.is_open() != true){
cout<<"open failed"<<endl;
return 0;
}
string l;
while(!ip.eof()){
getline(ip, l);
cout<<l<<endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
注意:我仍然需要添加一些处理代码
if(l == "???? ???????"){
string s = l.substr(0, 4);
cout<<s<<" is what you are looking for"<<endl;
}
Run Code Online (Sandbox Code Playgroud) 我正在学习仪器,所以我创建了一个简单的应用程序,让用户输入要分配的多个兆字节(MB).我使用Instruments中的"Allocations"工具来确保分配这些确切数量的数据.但是,我总是看到仪器中分配的内存比我预期的多.
我做了以下
func allocateMemoryOfSize(numberOfBytes: Int) {
var bytesArray = [Int8]()
for i in 0 ..< numberOfBytes {
bytesArray.append(Int8(i % 7))
}
}
Run Code Online (Sandbox Code Playgroud)
我检查了很多问题,我找到了一个替代方案:
func allocateMemoryOfSize(numberOfBytes: Int) {
var imageData = UnsafeMutablePointer<Int8>.alloc(numberOfBytes)}
Run Code Online (Sandbox Code Playgroud)
但我仍然分配更多的内存.当我分配10 MB时,这是仪器中的结果:
在运行allocateMemoryOfSize函数之前:
因此,该函数分配大约22 MB而不是10.我究竟做错了什么?或者这是额外的内存管理?
在C中我想将进程的输出从stdout重定向到写入"共享内存段",可以将其视为char数组或带有指针的字符串
我知道有dup2但是它将文件描述符作为参数不是指向数组的指针.有没有办法将其重定向到字符串?
我是matlab的新手.我想实现KNN算法.我试图阅读fitcknn分类器,但我无法得到它.我有矩阵x有4个输入向量(每个向量有3个特征)
1 2 3
5 19 20
1 2 4
8 19 21
Run Code Online (Sandbox Code Playgroud)
我想得出一个输出矩阵Y,它给出了输入矩阵的每个向量的最近邻居(按顺序).例如:在这种情况下,y将是
3 2 4
4 3 1
1 2 4
2 3 1
Run Code Online (Sandbox Code Playgroud)
说明:矩阵Y的第一行表示与向量1最接近的向量是:向量3,然后是向量2,然后是向量4.
是否有库进行此分类(使用余弦距离作为相似函数)?谢谢.
我转发此功能以从列表x中删除数字
(defun rm-nums (x)
(cond
((null x) nil)
(t (mapcar 'numberp x))))
Run Code Online (Sandbox Code Playgroud)
但是,当我输入(rm-nums '(32 A T 4 3 E))
回报(T NIL NIL T T NIL)
我想要它而不是返回T或Nil,我希望它返回仅导致NIL的值[这不是数字]所以这个例子应该返回(A T E)
我应该使用mapcar WITHOUT recursion或iteration或bultin函数"remove-if "
我认为它与名为apply-append的东西有关但我对此一无所知.任何帮助?
我有一个名为的函数show_notification()
,当用户点击按钮时我会调用它.关键是,一旦他点击[如下面的函数],我不想显示通知,我想在特定的time= hours:mins
地方显示此通知.小时和分钟是两个整数,具有我想要的时间值[例如小时= 22和分钟= 40 ..意思是在22:40 [10:40 pm]发出此通知.顺便说一句,这个警报应该每天同时重复.
public void show_notification() {
CharSequence notify_msg="Don't foget!";
CharSequence title= "you ve been notified by My app";
CharSequence details= "It works!";
NotificationManager nm= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notify= new Notification(android.R.drawable.stat_notify_more,
notify_msg,
System.currentTimeMillis());
Context mycontext= ActA.this;
Intent myintent= new Intent (mycontext, ActA.class);
PendingIntent pending= PendingIntent.getActivity(mycontext, 0, myintent, 0); ///0's are not applicable here
notify.setLatestEventInfo(mycontext, title, details, pending);
nm.notify(0, notify);
}
Run Code Online (Sandbox Code Playgroud)
我希望你能详细回答,因为我是一个非常新的开发者.
在下面的代码中,我是否放置"this->"或删除它并不重要.它在两种情况下都给出相同的输出和结果.那么,在C++中使用"this"指针有什么意义呢?还有其他必要的用法吗?谢谢.
#include<iostream>
using namespace std;
class square{
int l;
int w;
public:
square(int x, int y){
w = x;
l = y;
}
int getArea(){
return w * l;
};
bool AreaSmallerThan(square c){
if(this->getArea() < c.getArea())
return true;
else
return false;
}
};
int main(){
square A(2,3);
square B(1,3);
if(A.AreaSmallerThan(B))
cout<<"A is smaller than B."<<endl;
else
cout<<"A is NOT smaller than B."<<endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我有这个从infile到outfile的复制代码,问题是在outfile的末尾添加了很多垃圾
ssize_t nread;
int bufsize=512;
char buffer[bufsize];
while ( (nread=read(infile, buffer, bufsize)>0))
{
if( write(outfile, buffer, bufsize)<nread )
{
close(outfile); close(infile); printf("error in write loop !\n\n");
return (-4);
}
}
if( nread == -1) {
printf ("error on last read\n"); return (-5);
}//error on last read /
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能解决这个问题?
当我调用我的类的构造函数时,我得到注释中显示的错误(当我删除数组部分时,一切都很顺利).这是因为数组的错误声明seq
吗?
public class FibIt implements SeqIt{
public int counter;
public int ptr;
public int [] seq;
public FibIt(Fib x)
{ counter=0;
ptr=0;
seq[0]=x.first1; //gives me an error here saying Exception in
//thread "main" java.lang.NullPointerException
//at FibIt.<init>(FibIt.java:9)
//at Main.main(Main.java:6)
seq[1]=x.first2;
for (int i=2; seq[i-1]<=x.last; i++)
{seq[i]=seq[i-1]+seq[i-2];}
}
@Override
public int func2() {
// TODO Auto-generated method stub
ptr++;
return seq[ptr-1];
}
}
Run Code Online (Sandbox Code Playgroud)