小编Roh*_*har的帖子

从对象 C++ 中的文件读取内容时发生分段错误

在我的代码中,我首先将姓名和手机号码存储在一个对象中,然后使用 fstream.write() 方法将该对象写入一个文本文件。它成功地工作,但是当我将写入的内容读入另一个对象并调用显示方法时,它会正确显示数据,但是在打印数据后却给了我分段错误。这是我的代码 -

#include<iostream>
#include<fstream>
using namespace std;
class Telephone
{
private:
    string name="a";
    int phno=123;
public:
    void getTelephoneData()
    {
        cout<<"Enter Name:";
        cin>>name;
        cout<<"Enter Phone Number:";
        cin>>phno;
    }
    void displayData()
    {
        cout<<"Name\t\tPhone no"<<endl;
        cout<<name<<"\t\t"<<phno<<endl;
    }

    void getData() {
        Telephone temp;
        ifstream ifs("Sample.txt",ios::in|ios::binary);
        ifs.read((char*)&temp,sizeof(temp));
        temp.displayData();
    }   
};
int main()
{
    Telephone t1;
    t1.getTelephoneData();
    cout<<"----Writing Data to file------"<<endl;
    ofstream ofs("Sample.txt",ios::out|ios::binary);
    ofs.write((char*)&t1,sizeof(t1));
    ofs.close();
    t1.getData();
}
Run Code Online (Sandbox Code Playgroud)

请帮助我我错的地方。提前致谢...!

c++ file-io fstream file c++14

4
推荐指数
1
解决办法
1330
查看次数

夜间模式颜色不适用于回收站视图背景

我想为我的 android 应用程序实现夜间模式,所以我使用 Theme.AppCompat.DayNight 主题来实现夜间模式。但是我必须在夜间模式下自定义工具栏和回收站视图的颜色。

为此,我在 attrs.xml 文件中声明了该属性,并在 recyclerview 中使用该属性作为背景。

这是 attrs.xml 文件

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="ds">
        <attr name="rv_color" format="color"/>
    </declare-styleable>
</resources>
Run Code Online (Sandbox Code Playgroud)

这是回收站视图

 <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="?attr/rv_color"
        android:overScrollMode="never"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">
Run Code Online (Sandbox Code Playgroud)

现在对于样式,我已经为夜间模式声明了styles.xml 和styles.xml(夜间)。

这是styles.xml

<style name="AppTheme" parent="Theme.AppCompat.DayNight">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@android:color/white</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:textColorPrimary">@color/colorPrimary</item>
    <item name="android:windowDisablePreview">false</item>
    <item name="rv_color">#FF0000</item>
</style>
Run Code Online (Sandbox Code Playgroud)

这是styles.xml(晚上)

<style name="AppTheme" parent="Theme.AppCompat.DayNight">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@android:color/white</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item …
Run Code Online (Sandbox Code Playgroud)

android android-styles android-recyclerview android-night-mode android-dark-theme

2
推荐指数
1
解决办法
1558
查看次数

Volley: [355] NetworkDispatcher.processRequest: 未处理的异常 java.lang.IllegalArgumentException

您好,我正在尝试运行以下代码将数据发布到在线 MySQL 数据库

    if (data.getCount() > 0) {
                    data.moveToFirst();
                    do {
                        save(orderId,client, data.getString(0),data.getString(3),String.valueOf(finalCost),data.getString(4),longitude,latitude,"_",progressDialog);
                    } while (data.moveToNext());
                       data.close();
                    mydb.clearCart();

    private void save(final String orderId, final String client, final String prodid, final String Seller, final String amount, final String quantity, final double longi, final double lat, final String location, final ProgressDialog progressDialog) {
    String URL_ORDER = "https://foodfuzz.co.ke/foodfuzzbackend/market/orders/order.php";
    StringRequest orderStringRequest = new StringRequest(Request.Method.POST, URL_ORDER,
            //android M

            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        JSONObject orderObject = new JSONObject(response);
                        String …
Run Code Online (Sandbox Code Playgroud)

android android-volley

2
推荐指数
1
解决办法
3074
查看次数

Chrome 自定义选项卡在 Chrome 中作为新选项卡打开,而不是在应用程序内打开,为什么?

如何在不打开后台 Google Chrome 的情况下在应用程序中打开自定义选项卡...

这是我的代码

String a="http://www.gpamravati.ac.in/gpamravati";
        CustomTabsIntent.Builder builder=new CustomTabsIntent.Builder();
        CustomTabsIntent custom=builder.build();
        custom.intent.setPackage("com.android.chrome");
        builder.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary));
        custom.launchUrl(this, Uri.parse(a));
Run Code Online (Sandbox Code Playgroud)

当我单击网站菜单项时,它会调用 chrome 自定义选项卡

打开是这样的

java android android-customtabs

-1
推荐指数
1
解决办法
2203
查看次数