Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Find if a shell file exists
QtWS25 Last Chance

Find if a shell file exists

Scheduled Pinned Locked Moved Unsolved C++ Gurus
4 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sylas
    wrote on last edited by
    #1

    Here is my C++ file:
    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;
    int main()
    {
    cout << "rentrez nom du shell\n";//give me the name of the shell
    string shell("");//empty string
    cin >> shell;
    string path="/home/sylvain/";
    string total=path+shell;
    total='"'+path+shell+'"';
    cout << total <<endl;// Ok jusque là
    //ifstream monFlux(total);
    ifstream monFlux("/home/sylvain/essai"); //On essaye d'ouvrir le fichier
    if(monFlux) cout << "Ce fichier existe\n";
    else cout << "fichier inexistant." << endl;
    }
    Impossible to replace (in the ifstream line) what is in the parenthesis by the string "total". What shall i do if I want that the above file works well , with a whatever shell file ? Many thanks for your answer.

    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Why this line:

      total='"'+path+shell+'"';
      

      ?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      0
      • jsulmJ jsulm

        Why this line:

        total='"'+path+shell+'"';
        

        ?

        S Offline
        S Offline
        Sylas
        wrote on last edited by
        #3

        @jsulm I thought it was possible to put that inside the parenthesis of ifstream. Now i Think it is impossile. I cannot introduce introduce a string in the middle of a program line. Isnt'it ?

        1 Reply Last reply
        0
        • jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #4

          It does not make any sense to add " to a string containing a path - it will become invalid path! Because " is not allowed in paths.
          If you want the path to be enclosed in " if you print it out then do:

          cout << '"' << total << '"' <<endl;
          

          This one I don't understand:

          I cannot introduce introduce a string in the middle of a program line. Isnt'it ?
          

          What do you mean?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved